ASP Page_Load元素值为null

ASP Page_Load Element value is null

本文关键字:null 元素 Load Page ASP      更新时间:2023-09-26

我有一个javascript函数,它在page_load期间执行,其目的是处理一些客户端工作站值,并将值设置为元素。问题是,在成功获得客户端值后,元素在codeehind中仍然为null,但在ASP-UI中却不是。

注意:我成功地获得了客户端工作站的数据,这就是为什么我需要javascript。我只是在这里使用了"新值",例如

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:

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

能请人帮我一下吗?谢谢!

尝试在预渲染阶段中注册脚本

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