views:

35

answers:

3

Hi,

I would like to raise error by myself and use reqularexpressionvalidator to show it's text. (My idea is to reuse this control.) I don't remember what property should I use, and what to assign to show the message from control. Can anybody help me please? How to raise error for this control from code?

+1  A: 

probably it is ErrorMessage

ErrorMessage="Please enter a 4 digit number!"

or with more details, use this syntax

    <asp:TextBox runat="server" id="txtNumber" />
    <asp:RegularExpressionValidator id="accessID"
    ControlToValidate = "ID of input control to validate"
    ValidationExpression = "the regular expression pattern to test against"
    ErrorMessage = "message to display in ValidationSummary control"
    Text = "message to display in control"
    ForeColor = "color value"
    BackColor = "color value"
    runat="server" />
Asad Butt
A: 

Message shows the text next to the control Error shows the text after validation fails

Some people usually go with Message="*" and Error="Field cannot have special characters" and ValidationExpression is the regex to compare against, remember to set the ControlToValidate to the Id of your input control.

F.Aquino
A: 

Assign the validator to a control using it's ControlToValidate property. Set the text using it's ErrorMessage property.

Then, if you'd like it to show, you can call Page.IsValid on the server, like this:

void ValidateBtn_Click(Object sender, EventArgs e) 
       {
          if (Page.IsValid) 
          {
            // do something
          }
       }
womp