selva kumar

selva kumar

  • NA
  • 557
  • 190k

code doesnot working properly?

May 9 2014 6:39 AM
i need to display client ip to label from hiddenfield,i have written below code but it does not working ,,,can anyone help me out...its urgent..

Source:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>


  <script type="text/javascript">
  function Disp() {
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = "http://jsonip.appspot.com/?callback=DisplayIP";
  document.getElementsByTagName("head")[0].appendChild(script);
  };
  function DisplayIP(response) {
  //  document.getElementById("ipaddress").innerHTML = "Your IP Address is " + response.ip;
  alert(response.ip)

  document.getElementById("<%=mm.ClientID %>").value = response.ip;
  }
</script>

</head>
<body>
  <form id="form1" runat="server">
  <div>
  <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="Disp();"
  onclick="Button1_Click"/>
  <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
  <asp:HiddenField ID="mm" runat="server" />

  </div>
  </form>
</body>
</html>


C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {

  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  Label1.Text = mm.Value;
  }
}

Answers (2)