a page can have only one server-side form tag
Asked Answered
U

7

27

I am using master page and when I run this page, it shows the following error message:

a page can have only one server-side form tag

How can I solve this problem?

Uranyl answered 26/5, 2010 at 7:8 Comment(4)
It's an intrinsic part of ASP.NET web forms that only one server side form tag can be used on a rendered page. You can have other forms, they just can't have the runat="server" attribute on them, IIRC.Earthlight
Completely remove the tags from the masterpagePuccini
@RussCam Good pattern is form tag in Master or in Nested contentPage ?Rigobertorigor
@Rigobertorigor good pattern is to no longer use Webforms, but a framework that better fits the paradigm such as MVC :) Having it in the Master page or Content page is going to to depend on whether there are controls in the Master that need to be inside of the form.Earthlight
C
29

I think you did like this:

<asp:Content ID="Content2" ContentPlaceHolderID="MasterContent" runat="server">
  <form id="form1" runat="server">

 </form>
</asp:Content>

The form tag isn't needed. because you already have the same tag in the master page.

So you just remove that and it should be working.

Cyanine answered 18/11, 2011 at 11:50 Comment(2)
your master page have one form already. nested forms are not allowedHolliman
Good pattern is form tag in Master or in Nested contentPage ?Rigobertorigor
T
11

It sounds like you have a form tag in a Master Page and in the Page that is throwing the error.

You can have only one.

Thicken answered 26/5, 2010 at 7:14 Comment(0)
A
5

Use only one server side form tag.

Check your Master page for <form runat="server"> - there should be only one.

Why do you need more than one?

Apicella answered 26/5, 2010 at 7:10 Comment(2)
this page contain only contantplace holder i created new page and running this page after that this show error.Uranyl
@Manoj Wadhwani - Make sure both pages have only one server side form tag.Apicella
P
5

Does your page contain these

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:content>

tags, and are all your controls inside these? You should only have the Form tags in the MasterPage.


Here are some of my understanding and suggestion:

Html element can be put in the body of html pages and html page does support multiple elements, however they can not be nested each other, you can find the detailed description from the W3C html specification:

The FORM element

http://www.w3.org/MarkUp/html3/forms.html

And as for ASP.NET web form page, it is based on a single server-side form element which contains all the controls inside it, so generally we do not recommend that we put multiple elements. However, this is still supported in ASP.NET page(master page) and I think the problem in your master page should be caused by the unsupported nested element, and multiple in the same level should be ok. e.g:

In addition, if what you want to do through multiple forms is just make our page posting to multiple pages, I think you can consider using the new feature for cross-page posting in ASP.NET 2.0. This can help us use button controls to postback to different pages without having multpile forms on the page:

Cross-Page Posting in ASP.NET Web Pages

http://msdn2.microsoft.com/en-us/lib...39(VS.80).aspx

http://msdn2.microsoft.com/en-us/lib...40(VS.80).aspx

Puccini answered 26/5, 2010 at 7:37 Comment(0)
D
1

Sometime when you render the current page as shown in below code will generate the same error

StringWriter str_wrt = new StringWriter();
HtmlTextWriter html_wrt = new HtmlTextWriter(str_wrt);
Page.RenderControl(html_wrt);
String HTML = str_wrt.ToString();

so how can we sort it?

Drakensberg answered 19/9, 2013 at 12:20 Comment(2)
this is my exact problem did you find anything to fix this?Inurn
This is the issue here also.Aardwolf
A
1

please remove " runat="server" " from "form" tag then it will definetly works.

Apuleius answered 31/1, 2019 at 7:8 Comment(0)
P
0

If you render the page then you need to call Response.End() to prevent rendering the whole page.

Pasteup answered 1/3, 2023 at 14:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.