我可以使用Ajax和asp.net 4.5 .NET Framework FileUpload控件来上传多个文件吗?

时间:2023-02-02 03:38:42

I have to verify if the UploadFile control of asp.net 4.5 .NET Framework like this:

我必须验证asp.net 4.5 .NET Framework的UploadFile控件是否像这样:

<asp:FileUpload runat="server" AllowMultiple="true"/>

can be use with Ajax without Ajax Toolkit File Upload for uploading multiple files.

可以在没有Ajax Toolkit File Upload的情况下使用Ajax来上传多个文件。

I have seen those threads :

我见过那些线程:

but they are too old for my needs and they havn't give me answers.

但是它们对我的需求太老了,他们没有给我答案。

The person who worked on the project before me said that he had a problem with this control in a previous version and he was forced to use Ajax Toolkit File Upload.

在我之前从事这个项目的人说他在之前的版本中遇到了这个控件的问题,他*使用Ajax Toolkit File Upload。

Thank you in advance.

先谢谢你。

1 个解决方案

#1


0  

I have found something that is the beginning of an answer.

我找到了一些答案的开头。

Using an Ajax's UpdatePanel like this:

像这样使用Ajax的UpdatePanel:

<asp:ScriptManager ID="ToolkitScriptManager1" runat="Server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
   <ContentTemplate>
        <asp:FileUpload ID="fileUpload1" runat="server" AllowMultiple="true"/>
        <asp:Button ID="btnDoSomething" runat="server" Text="Do something" />
    </ContentTemplate>

    <Triggers>
        //Prevents postback and refresh of the page.
        <asp:AsyncPostBackTrigger ControlID="btnDoSomething" />
    </Triggers>        
</asp:UpdatePanel>

But, you can't properly upload files without a post back. For that, we have to add another button which will trigger the postback:

但是,如果没有回复,您无法正确上传文件。为此,我们必须添加另一个触发回发的按钮:

<asp:Button ID="btnUpload" runat="server" Text="Upload" />

And by adding it to <Triggers> tag:

并将其添加到 标记:

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="btnDoSomething" /> //Without post back
    <asp:PostBackTrigger ControlID="btnUpload" />  //With post back
</Triggers>

#1


0  

I have found something that is the beginning of an answer.

我找到了一些答案的开头。

Using an Ajax's UpdatePanel like this:

像这样使用Ajax的UpdatePanel:

<asp:ScriptManager ID="ToolkitScriptManager1" runat="Server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
   <ContentTemplate>
        <asp:FileUpload ID="fileUpload1" runat="server" AllowMultiple="true"/>
        <asp:Button ID="btnDoSomething" runat="server" Text="Do something" />
    </ContentTemplate>

    <Triggers>
        //Prevents postback and refresh of the page.
        <asp:AsyncPostBackTrigger ControlID="btnDoSomething" />
    </Triggers>        
</asp:UpdatePanel>

But, you can't properly upload files without a post back. For that, we have to add another button which will trigger the postback:

但是,如果没有回复,您无法正确上传文件。为此,我们必须添加另一个触发回发的按钮:

<asp:Button ID="btnUpload" runat="server" Text="Upload" />

And by adding it to <Triggers> tag:

并将其添加到 标记:

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="btnDoSomething" /> //Without post back
    <asp:PostBackTrigger ControlID="btnUpload" />  //With post back
</Triggers>