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?
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>