Search code examples
asp.nethtmlvalidationrequiredfieldvalidator

asp:RegularExpressionValidator


So the user clicks on a hyperlink 'add data' which brings them to a new page where they will have to enter text into 3 textboxes and then click the button. When the button is clicked (an error msg will show-if one of the text boxes is left empty)

I've tried

 <td>
                <asp:TextBox ID="TextBox1" runat="server" MaxLength="20" />
                <asp:RegularExpressionValidator ID="ValidationTextBox1" runat="server" ControlToValidate="TextBox1" ErrorMessage="Please enter" />
             </td>

but when i test this, empty no data into the text box and click the button I receive no error?? please advise


Solution

  • User Required Field Validator control, not the Regular Expression one.

     <asp:TextBox id="Text1" 
          Text="Enter a value" 
          runat="server"/>
    
     <asp:RequiredFieldValidator id="RequiredFieldValidator1"  
          ControlToValidate="Text1"
          Text="Required Field!" 
          runat="server"/>
    

    MSDN