一个页面只能有一个服务器端表单标记

时间:2022-03-19 15:55:59

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?

我怎么解决这个问题?

5 个解决方案

#1


15  

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.

所以你只需删除它,它应该工作。

#2


9  

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.

你只能有一个。

#3


4  

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.

标签,这些都是你的控件吗?您应该只在MasterPage中有Form标签。


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:

Html元素可以放在html页面的主体中,而html页面确实支持多个元素,但是它们不能互相嵌套,你可以从W3C html规范中找到详细的描述:

The FORM element

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

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:

对于ASP.NET Web表单页面,它基于单个服务器端表单元素,其中包含其中的所有控件,因此通常我们不建议我们放置多个元素。但是,ASP.NET页面(母版页)仍然支持这一点,我认为主页面中的问题应该是由不受支持的嵌套元素引起的,并且同一级别中的多个应该没问题。例如:

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:

此外,如果您想通过多个表单执行的操作只是将我们的页面发布到多个页面,我认为您可以考虑使用新功能在ASP.NET 2.0中进行跨页面发布。这可以帮助我们使用按钮控件回发到不同的页面而不需要在页面上有多个表单:

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...39(VS.80).aspx

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

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

#4


3  

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?

为什么你需要不止一个?

#5


0  

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?

那么我们如何排序呢?

#1


15  

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.

所以你只需删除它,它应该工作。

#2


9  

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.

你只能有一个。

#3


4  

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.

标签,这些都是你的控件吗?您应该只在MasterPage中有Form标签。


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:

Html元素可以放在html页面的主体中,而html页面确实支持多个元素,但是它们不能互相嵌套,你可以从W3C html规范中找到详细的描述:

The FORM element

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

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:

对于ASP.NET Web表单页面,它基于单个服务器端表单元素,其中包含其中的所有控件,因此通常我们不建议我们放置多个元素。但是,ASP.NET页面(母版页)仍然支持这一点,我认为主页面中的问题应该是由不受支持的嵌套元素引起的,并且同一级别中的多个应该没问题。例如:

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:

此外,如果您想通过多个表单执行的操作只是将我们的页面发布到多个页面,我认为您可以考虑使用新功能在ASP.NET 2.0中进行跨页面发布。这可以帮助我们使用按钮控件回发到不同的页面而不需要在页面上有多个表单:

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...39(VS.80).aspx

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

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

#4


3  

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?

为什么你需要不止一个?

#5


0  

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?

那么我们如何排序呢?