Click here to Skip to main content
15,903,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two textbox, two requiredfieldvalidator and two buttons. i want to when i click on button1 only textbox1 should be validate. and when click on button2 textbox2 should be validate. can anyone tell me how can i do this.
please help
Posted

use Validation Groups
Specifying Validation Groups[^]
set same validation group for button1 and requiredfieldvalidator1 and another validation group for button2 and requiredfieldvalidator2
 
Share this answer
 
v2
use ValidationGroup Property
    <asp:requiredfieldvalidator id="Req9" runat="server"  ValidationGroup="a"
                    ErrorMessage="Enter PINno"></asp:requiredfieldvalidator>  
 
     <asp:requiredfieldvalidator id="Req10" runat="server" controltovalidate="TextBox2" ValidationGroup="b"
                    ErrorMessage="Enter PINno"></asp:requiredfieldvalidator> 
 
<asp:button id="btnsubmit" runat="server" ValidationGroup="a" 
                     Text="Button1" onclick="btnsubmit_Click1"/>  
 
<asp:button id="btnsubmit1" runat="server" ValidationGroup="b" 
                     Text="Button2" onclick="btnsubmit1_Click1" />



Group the Textbox1 with Button1 and Textbox2 with Button2
 
Share this answer
 
v6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900