VALIDATE DIV TAG SEPARATELY

Goti Bandu

Total Post:119

Points:835
Posted by  Goti Bandu
 837  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. Sumit Kesarwani

    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>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!