Validate Div tag separately

Total Post:119

Points:835
 1085  View(s)
Ratings:
Rate this:

I have 3 div tags.

Each having no. of textboxes and button. Each textbox having validation. For all button causesvalidation property is true. If I click "button1" in "div1" tag will cause validation of other textbox in other div tags.

I don't want to do this. How to avoid this?

  1. Post:378

    Points:2694
    Re: Validate Div tag separately

    Hi Goti, 


    Set the ValidationGroup property of the elements in each div to a separate validation group.

    <asp:TextBox ID="TextBox1" runat="server"
    ValidationGroup="Div1"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="Div1"></asp:Button>
    <asp:RequiredFieldValidator ControlToValidate="Textbox1" ValidationGroup="Div1" ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
    <asp:TextBox ID="TextBox2" runat="server" ValidationGroup="Div2"></asp:TextBox>
    <asp:Button ID="Button2" runat="server" Text="Button" ValidationGroup="Div2"></asp:Button>
    <asp:RequiredFieldValidator ControlToValidate="Textbox2" ValidationGroup="Div2" ID="RequiredFieldValidator2" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
    <asp:TextBox ID="TextBox3" runat="server" ValidationGroup="Div3"></asp:TextBox>
    <asp:Button ID="Button3" runat="server" Text="Button" ValidationGroup="Div3"></asp:Button>
    <asp:RequiredFieldValidator ControlToValidate="Textbox3" ValidationGroup="Div3" ID="RequiredFieldValidator3" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>

      Modified On Apr-05-2018 04:20:40 AM

Answer