我使用的是ajax工具包asyncFileUpload控件
我遇到问题,我的服务器端事件没有被触发,发现这个帖子Hidden/Shown AsyncFileUpload Control Doesn't Fire Server-Side UploadedComplete Event
我在表单中插入了我的上传器,并使用此属性enctype="multipart/form-data" method="post"
此上传器位于我的网页表单中,位于母版页
中添加此属性后,我收到此错误
A page can have only one server-side Form tag.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: A page can have only one server-side Form tag.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
这是我的网络表单
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<form id="Form1" enctype="multipart/form-data" method="post" action="target_url"
runat="server">
<div id="Div1" runat="server">
Just some time to make sure that the page doesn't get reloaded after uploading:
<%=DateTime.Now %><br />
<ajaxToolkit:AsyncFileUpload ID="FileUpload" runat="server" OnUploadedComplete="FileUpload_UploadCompleted"
OnClientUploadComplete="FileUpload_ClientUploadCompleted" OnClientUploadError="uploadError"
OnLoad="FileUpload_OnLoad" />
<asp:Image runat="server" ID="imgUpload" src="" />
<asp:Label runat="server" ID="lblerror" Text="" />
</div>
</form>
</asp:Content>
答案 0 :(得分:1)
您的MasterPage
已有form
元素。嵌套的form
不允许......
我对ajaxToolkit:AsyncFileUpload
了解不多,但由于它是服务器控件,因此应更改父form
的属性。您是否尝试过移除下面代码的表单?
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div id="Div1" runat="server">
Just some time to make sure that the page doesn't get reloaded after uploading:
<%=DateTime.Now %><br />
<ajaxToolkit:AsyncFileUpload ID="FileUpload" runat="server" OnUploadedComplete="FileUpload_UploadCompleted"
OnClientUploadComplete="FileUpload_ClientUploadCompleted" OnClientUploadError="uploadError"
OnLoad="FileUpload_OnLoad" />
<asp:Image runat="server" ID="imgUpload" src="" />
<asp:Label runat="server" ID="lblerror" Text="" />
</div>
</asp:Content>
另一种可能的解决方案:
&#34;流行#34; a&#34;模态&#34;仅包含form
表单的file upload control
。这将解决嵌套表单问题。但是,它确实改变了功能。
答案 1 :(得分:1)
作为一个非常脏的黑客尝试添加在表单前添加<form></form>
,并从您的嵌套表单中取出runat =“server”。
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
**<form></form>**
<form id="Form1" enctype="multipart/form-data" method="post" action="target_url"
>
<div id="Div1" runat="server">
Just some time to make sure that the page doesn't get reloaded after uploading:
<%=DateTime.Now %><br />
<ajaxToolkit:AsyncFileUpload ID="FileUpload" runat="server" OnUploadedComplete="FileUpload_UploadCompleted"
OnClientUploadComplete="FileUpload_ClientUploadCompleted" OnClientUploadError="uploadError"
OnLoad="FileUpload_OnLoad" />
<asp:Image runat="server" ID="imgUpload" src="" />
<asp:Label runat="server" ID="lblerror" Text="" />
</div>
</form>
</asp:Content>
过去这对我有用 - 当被迫使用WebForms时。我不知道为什么,但我发现WebForms有很多。
如果你想写这样的代码,你真的应该切换到MVC。即使这确实有效,也不是我所说的解决方案。 WebForms并不是为此而设计的。