Goals:

Steps:

  1. Create a new ASP.NET Web Application project in Visual Studio.
  2. Add a Button and a Literal to the page:
    <asp:Button ID="PostbackButton" runat="server" onclick="PostbackButton_Click"
        
    Text="PostbackButton" />
    <
    asp:Literal ID="statusLiteral" runat="server"></asp:Literal>
    Add also code for the PostbackButton_Click method:
    protected void PostbackButton_Click(object sender, EventArgs e)
    {
        statusLiteral.Text =
    "PostbackButton_Click called";
    }
  3. RequiredFieldValidator
  4. ValidationSummary
  5. Validators can be grouped by values of the ValidationGroup property. This property can be set for validator controls and all controls that can cause validation, in particular Button controls..
  6. CompareValidator
  7. RangeValidator
  8. RegularExpressionValidator
  9. CustomValidator
  10. The text displayed by a validator control can use HTML tags. This feature allows to use in example image to notify the user about an error:

    using the following code:
    <asp:CustomValidator ID="CustomValidator1" runat="server"
       
    ControlToValidate="TextBox11" Display="Dynamic"
       
    ErrorMessage="<img src='exclamation.png' />"
       
    onservervalidate="CustomValidator1_ServerValidate"
       
    ClientValidationFunction="CustomValidator1_ClientValidate"
       
    ValidationGroup="ValGroup4">

[Source code]