WiseMonk
WiseMonk

Reputation: 54

Accessing codebehind field values through ASP.NET HTML code

simple question

in code behind(.cs) we have

string error="11000114S";

in ASP (.aspx) we have:

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

So how to do this, assign value from cs-> saved error list to html ?

Upvotes: 0

Views: 395

Answers (3)

Shan Plourde
Shan Plourde

Reputation: 8726

You can assign error messages dynamically to your validators in your code behind. I.e.:

this.textValidator.ErrorMesssage = error;

Upvotes: 0

Junaid
Junaid

Reputation: 1755

this should do

protected string error="11000114S";

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

Upvotes: 0

Ian G
Ian G

Reputation: 30244

It is as simple as adding this to your .cs .. if I understand you correctly

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

Upvotes: 2

Related Questions