2015-04-07 26 views
0

我有一個在page_load期間執行的javascript函數,其目的是處理某些客戶端工作站值並將值設置爲元素。問題是成功獲取客戶端值後,元素在代碼隱藏中仍然爲空,但不在ASP-UI中。ASP Page_Load元素值爲空

注:我成功地獲得客戶端工作站數據,這就是爲什麼我需要它的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'; 
} 

可以請人幫助我,這多虧了!

回答

0

嘗試在預渲染階段註冊腳本

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

確定讓我來試試感謝 – zxc

+0

抱歉:(但仍文本爲空。 – zxc