0

I have 2 buttons and other controls in a page. Button1 has validation group Validation1 and Button2 has Validation2. When I click Button1, controls with Validation2 are validated, which is not supposed to happen. How can I avoid this?

LordHits
  • 5,054
  • 3
  • 38
  • 51
hima
  • 610
  • 3
  • 10
  • 24

1 Answers1

1

Have you putted validation group to all the controls.You need to give validation groups controls to all the fields including validator controls. Just like following.

<form id="form1" runat="server">
<div>
     <asp:TextBox runat="server" ID="firstTextBox" ValidationGroup="vg1"></asp:TextBox>
     <asp:RequiredFieldValidator runat="server" ID="requiredFirst" ControlToValidate="firstTextBox" ValidationGroup="vg1"></asp:RequiredFieldValidator>
     <asp:Button runat="server" ValidationGroup="vg1" Text="SaveData" ID="btnSaveFirst"/>
</div>
    <div>
     <asp:TextBox runat="server" ID="secondTextBox" ValidationGroup="vg2"></asp:TextBox>
     <asp:RequiredFieldValidator runat="server" ID="requiredSecond" ControlToValidate="secondTextBox" ValidationGroup="vg2"></asp:RequiredFieldValidator>
     <asp:Button runat="server" ValidationGroup="vg2" Text="SaveData" ID="btnSaveSecond"/>
</div>
</form>
Jalpesh Vadgama
  • 13,653
  • 19
  • 72
  • 94
  • Yes, I have done the same. What i had missed was, Page_ClientValidate. After adding this bit onclick of button, it seems to validate controls with respective ValidationGroups. Thank You very much for the help. – hima Jul 12 '13 at 08:14