2012-02-17 66 views
2

我使用Ajax工具包asyncFileUpload控制如何使用形式方法=「郵報」在asp.net web表單

我有我的服務器端事件不解僱的問題,發現這個帖子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

這是ASP .NET WebForms **吸引**的主要原因之一。 – Yuck 2012-02-17 15:18:14

+0

:D有沒有解決方案? – 2012-02-17 15:21:35

+1

切換到MVC :) – xandercoded 2012-02-17 15:22:04

回答

1

MasterPage已經有一個form元素。嵌套0​​s是不允許的...

我對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> 

另一個可能的解決方案:

「啪」 一個 「多態」 form只包含與file upload control表單。這將解決嵌套的表單問題。但是,它確實改變了功能。

+0

是的,我知道只有一個表單標籤是允許的,但我如何讓上傳工作? – 2012-02-17 15:21:08

+0

是的,但沒有表單標籤服務器端事件不會觸發 – 2012-02-17 15:27:21

+0

您的'MasterPage'是否有'form'? – xandercoded 2012-02-17 15:29:43

1

作爲一個非常骯髒的黑客嘗試添加一個<form></form>在您的窗體前,並採取runat =「服務器」出你的嵌套形式。

<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的目的不是爲了做到這一點。

相關問題