Pages

Monday, June 11, 2012

How to get client IP Address

How to get client IP Address / How to get machine IP Address.



  public string  getclientIP()
        {

            ManagementObjectSearcher objSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'");
            ManagementObjectCollection objCollection = objSearcher.Get();
            string Ip = "";
            foreach (ManagementObject obj in objCollection)
            {           
                string[] AddressList = (string[])obj["IPAddress"];
                foreach (string Address in AddressList)
                {

                  Ip=Address;
                    break;
                }             

            }
            return Ip;
        }

Thursday, June 7, 2012

How to get public IP Address of machine



        Dim client As New WebClient()


        ' Add a user agent header in case the requested URI contains a query.
        client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR1.0.3705;)")

        Dim baseurl As String = "http://checkip.dyndns.org/"

        Dim data As Stream = client.OpenRead(baseurl)
        Dim reader As New StreamReader(data)
        Dim s As String = reader.ReadToEnd()
        data.Close()
        reader.Close()
        s = s.Replace("<html><head><title>Current IP Check</title></head><body>", "").Replace("</body></html>", "").ToString()
        MessageBox.Show(s)

Saturday, March 24, 2012

how to get selected item from dropdownlist in javascript


var ddl=document.getElementById ("<%=DropDownList1.ClientID%>");
var text=ddl.options[ddl.selectedIndex].text;
alert(text); 

Friday, March 23, 2012

how to add remove items in dropdown list in java script

how to add remove items in dropdown list in java script in asp.net


it is very easy to add and remove items in javascript .

Here is the code for it...



<script type="text/javascript">
    function AddItem(Text,Value)
    {
        // Create an Option object for adding item to dropdownlist       
        var opt = document.createElement("option");

        // Add an Option object to Drop Down/List Box
        document.getElementById("DropDownList").options.add(opt);
        // Assign text and value to Option object
        opt.text = Text;
        opt.value = Value;

    }<script />


Enjoyyyy Programming..

Thursday, March 22, 2012

Call JavaScript function from code behind in asp.net

It is very easy to call javascript function from code behind asp.net .


In .cs code write


  string url = "yourpage.aspx?ManiFestNumber=" + value;
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "rates", "openWindow('" + url + "');", true);                  
       



in aspx page just write in this code 




<script type="text/javascript">

    function openWindow(url)
{
    var w = window.open(url, '', 'width=1,height=1,toolbar=0,status=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0');
    w.focus();
}





and Its done .........