Home > DeveloperSection > Forums > Validate Div tag separately
Goti Bandu

Total Post:119

Points:835
Posted on    August-27-2014 1:30 AM

 ASP.Net
Ratings:


 1 Reply(s)
 593  View(s)
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?



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-27-2014 2:50 AM

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>


Don't want to miss updates? Please click the below button!

Follow MindStick