Ad

.NET Two "forms" On A Page And Their Validators

- 1 answer

I have got a page that has 2 "forms" (What I mean by a form here is a Panel consisting of: textboxes, validators and a button).

(I got 2 here because one of them is actually on the MasterPage, shown all the time)

The problem is when you try to submit to one of the form, it will validate the other form, which of course is blank and invalid.

How do you solve this problem?

Thank you.

Ad

Answer

Your problem can be solved with asp.net ValidationGroups.

http://weblogs.asp.net/scottgu/archive/2004/10/24/246945.aspx

Basically, you group the controls to be validated using a uniquely named validation group. Like so:

<asp:Textbox ID="txt" runat="server" />
<asp:RequiredFieldValidator id="rfv" runat="server" ControlToValidate="txt" ValidationGroup="masterGroup">* Required!</asp:RequiredFieldValidator>
<br />
<asp:Button id="btnSubmitMaster" runat="server" Text="Submit!" ValidationGroup="masterGroup" />

If you group your inputs like this, then assign the validation group to the control that submits the form, the inputs in the other validation groups won't be validated.

Ad
source: stackoverflow.com
Ad