Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i use required field validator in my asp.net web page for text box and any other controls,
and after click on submit button they all are work fine,


but my problem is when i use button or linkbutton, on any other place at the same page
and when i click them : all required field validator also appear and i am not able to click on that button without fill all text box,

so plz provide me solution ,that validation are fix for perticulor button click:


my code is:

XML
<asp:TextBox ID="TxtUserID" Height="15px" placeholder="mail Id"  Width="180px"  CssClass="txtFinal" runat="server"
       ></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TxtUserID" ForeColor="Red" Font-Bold="true" ErrorMessage="**"></asp:RequiredFieldValidator>

     <asp:Button ID="BtnForSubmit" runat="server" Width="80px" Text="Submit"
         />




<asp:LinkButton ID="LinkButton2" PostBackUrl="http//:google.com" runat="server">Go Url</asp:LinkButton>




For Link button Click i am not want that validation is appear in the screen because i want validation only for button click:
Posted
Updated 7-Mar-13 0:47am
v4
Comments
Prakash Thirumoorthy 6-Mar-13 1:57am    
share your aspx coding.. then only we can find solution easily...

1 solution

Use ValidationGoup property.
Eg.:-
ASP.NET
<asp:textbox id="txt" runat="server"></asp:textbox>
 <asp:requiredfieldvalidator id="rfv" runat="server" errormessage="Enter Name."
                             Display="Dynamic" SetFocusOnError="true" 
                             ForeColor="Red"  
                             ValidationGroup="Group"
                             ControlToValidate="txt">
 </asp:requiredfieldvalidator>

Use same ValidationGoup for your button on which you want to perform validation.
ASP.NET
 <asp:button id="btnNext" runat="server" text="Next"
             ValidationGroup="Group" />

</asp:button>


Or you can set CausesValidation property of your link button to false.

Good luck.
 
Share this answer
 
v3
Comments
Arun kumar Gauttam 6-Mar-13 2:22am    
thanks
Raje_ 6-Mar-13 2:23am    
welcome!

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