2011-10-18 80 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;