2011-10-18 79 views
0

簡單的問題通過ASP.NET的HTML代碼訪問代碼隱藏字段值

在後面的代碼

(的.cs)我們有

string error="11000114S"; 
在ASP

(的.aspx),我們有:

<asp:TextBox ID="text" runat="server" EnableViewState="false" AutoPostBack="false"/> 
<asp:RequiredFieldValidator id="textValidator" runat="server" controlToValidate="text" 
errormessage=(our string error="11000114S")> 

那麼如何做到這一點,從cs->保存錯誤列表中的值分配給html?

+0

我不會建議從View返回代碼,儘量保持View儘量與代碼脫離,只需在代碼後面的代碼中初始化錯誤消息。 – sll

回答

2

如果我理解你正確地

string error="11000114S"; 
textValidator.ErrorMessage = error ; // or what ever you want 
0

本應該做的

protected string error="11000114S"; 

<asp:TextBox ID="text" runat="server" EnableViewState="false" AutoPostBack="false"/> 
<asp:RequiredFieldValidator id="textValidator" runat="server" controlToValidate="text" 
errormessage='<%# error %>'> 
0

您可以動態地分配錯誤消息,您的驗證這是因爲添加了此信息的.cs ..簡單的後面的代碼。 I.e .:

this.textValidator.ErrorMesssage = error;