I ran into this problem the other day. I have a masterpage with a login on it but I also have other forms that I am displaying in the child pages. How could I get both forms to work correctly?

MasterPage and Child Page with multiple forms

MasterPage and Child Page with multiple forms

The scenario is illustrated above… I have two forms in the masterpage (green) and one form in the child page (pink). The reason this is a problem is that if you put multiple forms on a page you cannot use the runat=”server” tag for all of them. Also when I hit the enter key for login the validation for the email form fires.  Only one form per page can use the runat server tag.. Otherwise you get an error similar to:


A page can have only one server-side Form tag.

Exception Details: System.Web.HttpException: A page can have only one server-side Form tag.


Not really a pleasant sight. When I first came to the realization about this I was a bit frightened. How can we overcome this?

First of all after some reading I found that it is possible to have multiple forms with the runat=”server” tag on the same page. The crux is that only one of the forms can be visible at a time. So the following would work.

I read this in a Microsoft article. Here is a link that describes the situation a little. It talks about why only one form makes sense, etc.


<form runat="server" id="First">Step 1</form>
<form runat="server" id="Second" visible="false">Step 2</form>
<form runat="server" id="Third" visible="false">Step 3</form>

Anyway the above scenario is good in some cases (i.e. – if you want to do a step through wizard). You could easily show the first step then as the user moves through the steps hide the finished step and then show the next step by changing the visible property.

Unfortunately this is not my scenario. I need all my forms to be visible all the time. Here is the simple fix and one that ensures one form (like my login form) will not fire another form (like my email form). Within your controls include a validation group.


<asp:TextBox ID="Password" runat="server" TextMode="Password" ValidationGroup="Login_Member" />

ValidationGroup=”Login_Member” causes my login form to act independently of other form controls on the page. Then you can use one form tag for the whole page and put as many controls in the middle as you want. An example might look like:


<form runat="server">
<asp:TextBox ID="UserName" runat="server" ValidationGroup="Login_Member" />
<asp:TextBox ID="Password" runat="server" TextMode="Password" ValidationGroup="Login_Member" />

<asp:TextBox id="email" runat="server" value="" />
<asp:TextBox id="email_verify" runat="server" value="" />
</form>

I simplified the code above to make it more readable. You would probably have some tables in there somewhere. Only one of my form groups uses the ValidationGroup tag.  (Login) Still I have found that this works ok… Neither form interferes with the other. Perhaps I should use the ValidationGroup tag for both. Experiment with that if you like… the important thing is that I can use each form independently and not hinder the other. Also I only use one form tag with runat=”server” so I don’t get that nasty error.