user2116972
user2116972

Reputation: 61

ASP C# RequiredFieldValidator

[textbox1]

[textbox2]

[button1] [linkbutton1]

i have 2 textboxes, 2 RequiredFieldValidator, button1 and linkbutton. the button1 and 2textboxes are working properly with RequiredFieldValidator, but if i click the linkbutton the RequiredFieldValidator also appears.

I want the RequiredFieldValidator focus only in button1. Is this possible?

Upvotes: 0

Views: 2762

Answers (3)

Praveen Nambiar
Praveen Nambiar

Reputation: 4892

Use ValidationGroup property of RequiredFieldValidator.

Set the ValidataionGroup="someName" for your textbox1-requiredfieldvalidator, textbox2- requiredfieldvalidator and your button1 control.

Note: Keep the name of the ValidationGroup same.

Upvotes: 0

Sachin
Sachin

Reputation: 40990

Set CausesValidation="false" in your link button markup like this

<asp:LinkButton ID="lnkButton" runat="server" CausesValidation="false"></asp:LinkButton>

Upvotes: 3

Parv Sharma
Parv Sharma

Reputation: 12705

you need to specify Validation Groups

 <asp:requiredfieldvalidator id="RequiredFieldValidator2"
      controltovalidate="AgeTextBox"
      validationgroup="PersonalInfoGroup"
      errormessage="Enter your age."
      runat="Server">
    </asp:requiredfieldvalidator>

Upvotes: 0

Related Questions