简体   繁体   English

ASP Page_Load元素的值为null

[英]ASP Page_Load Element value is null

I have a javascript function that gets executed during page_load, its purpose is to process some client workstation values and set the value to an element. 我有一个在page_load期间执行的javascript函数,其目的是处理一些客户端工作站的值并将该值设置为一个元素。 The problem is after successfully getting the client-value the element is still null in codebehind but not in ASP-UI. 问题是在成功获取客户值之后,该元素在代码隐藏中仍为空,但在ASP-UI中却不为空。

note : I'm successful at getting a client workstation data thats why i need javascript for it. 注意:我成功获取了客户端工作站数据,这就是为什么我需要JavaScript的原因。 I just used 'new value' here for example 我只是在这里使用“新价值”

C#: C#:

protected void Page_Load(object sender, EventArgs e)
{
    //GET CLIENT ADDRESS
    ScriptManager.RegisterStartupScript(this, this.GetType(), "getmac", "jsFunction();", true);
    string newValue = txt.text; //this is null
}

javascript: javascript:

function jsFunction() {
var txt = document.getElementById('<%=txt.ClientID %>');
txt.value = 'new value';
}

could please someone help me on this thanks! 可以请某人帮助我,谢谢!

try registering the script in Prerender phase 尝试在Prerender阶段注册脚本

 protected void Page_PreRender(object sender, EventArgs e)
 {
     ScriptManager.RegisterStartupScript(this, this.GetType(), "getmac", "jsFunction();", true);
     string newValue = txt.text;
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM