簡體   English   中英

ASP Page_Load元素的值為null

[英]ASP Page_Load Element value is null

我有一個在page_load期間執行的javascript函數,其目的是處理一些客戶端工作站的值並將該值設置為一個元素。 問題是在成功獲取客戶值之后,該元素在代碼隱藏中仍為空,但在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';
}

可以請某人幫助我,謝謝!

嘗試在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