Tuesday, 22 May 2012

ASP.Net ValidationGroup


ASP.NET ValidationGroup Property:
Definition and Usage of ValidationGroup in asp.net

The ValidationGroup property specifies which group of controls is validated on validation.

This property is mostly used when there are several buttons in a form.
 Syntax
 <asp:Button ValidationGroup="group" runat="server" />

Attribute        Description
   group          The validation group to validate.

The Following example give clear view of validation group in asp.net:


<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Welcome to ASP.NET Validation Group Example!!!
    </h2>
    <asp:Button ID="Button2" runat="server" Text="Button1" ValidationGroup="ValGroup1" />
    <asp:Button ID="Button1" runat="server" Text="Button2"  ValidationGroup="ValGroup2" />
     <asp:Button ID="Button3" runat="server" Text="Button3" ValidationGroup="ValGroup3" />
    <asp:Button ID="Button4" runat="server" Text="Button4"  ValidationGroup="ValGroup4" />
 
    <p>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator runat="server" ID="ref1" ErrorMessage="FillTextBox1" ControlToValidate="TextBox1"
        ValidationGroup="ValGroup1" ForeColor="Red"></asp:RequiredFieldValidator>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
             <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1"   ControlToValidate="TextBox2"
               ValidationGroup="ValGroup2" ErrorMessage="FillTextBox2"  ForeColor="Blue"> </asp:RequiredFieldValidator>
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
             <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2"  ControlToValidate="TextBox3"
             ValidationGroup="ValGroup3"  ErrorMessage="FillTextBox3"  ForeColor="Green"> </asp:RequiredFieldValidator>
        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
             <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator3"  ControlToValidate="TextBox4"
             ValidationGroup="ValGroup4" ErrorMessage="FillTextBox4"  ForeColor="Brown"></asp:RequiredFieldValidator>
      </p>
    <p>
       
    </p>
</asp:Content>




No comments:

Post a Comment