Javascript 如何在页面加载时将内部html的值转换为c#codebehind
嗨,我有java脚本中的代码,我需要代码后面的ip值Javascript 如何在页面加载时将内部html的值转换为c#codebehind,javascript,c#,asp.net,code-behind,Javascript,C#,Asp.net,Code Behind,嗨,我有java脚本中的代码,我需要代码后面的ip值 window.onload = function () { var script = document.createElement("script"); script.type = "text/javascript"; script.src = "http://www.telize.com/jsonip?callback=DisplayIP"; document.getElem
window.onload = function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://www.telize.com/jsonip?callback=DisplayIP";
document.getElementsByTagName("head")[0].appendChild(script);
};
function DisplayIP(response) {
**document.getElementById("ipaddress").innerHTML = "Your IP Address is " + response.ip;**
}
您可以在JavaScript中设置隐藏字段。在ASP代码中创建字段:
<input type="hidden" id="ipHidden" runat="server" />
在C#中:
您无法在服务器端获取IP字段,因为java脚本将在代码执行完成后执行。只有当页面完成其呈现时,您才能获取它Make
ipaddress
a服务器控件,并从中读取ip您知道您从客户端以codebehind的形式获取ip地址,而不使用类似的脚本吗?请参阅Request.ServerVariablesmake具有name属性“hdnIpAddress”或任何您喜欢的隐藏字段,并在服务器端检查Request.Params[“hdnIpAddress”]嘿,伙计们,我需要客户端机器的ip。我在客户端浏览器上使用此javascript,但无法进入页面加载。不是单击事件。我无法获取代码背后的值。我需要进入页面加载
function DisplayIP(response) {
document.getElementById("ipaddress").innerHTML = "Your IP Address is " + response.ip;
document.getElementById("ipHidden").value = response.ip;
}
string clientIP = ipHidden.value;