0

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 ?

1
  • I would NOT suggest reffer code behind from View, try to keep a View decoupled from code behind as much as possible, just initialize error message in code behind itself. Commented Oct 18, 2011 at 12:30

3 Answers 3

2

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
Sign up to request clarification or add additional context in comments.

Comments

0

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 %>'> 

Comments

0

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

this.textValidator.ErrorMesssage = error;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.