文件上传+ UpdatePanel的不首先点击工作 [英] FileUpload + UpdatePanel does not work on first click

查看:129
本文介绍了文件上传+ UpdatePanel的不首先点击工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不只是一个文件上传+ UpdatePanel的问题。

This is not just another FileUpload + UpdatePanel question.

我有,因为在许多类似的帖子称,一个UpdatePanel和我的窗体上的FileUpload控件。我也有一个PostBackTrigger设置为我的上传按钮。
有用。美中不足的是它永远不会在第一次点击工作。这就是:

I have, as stated in the many similar posts, an UpdatePanel and a FileUpload control on my form. I also have a PostBackTrigger set up for my upload button. It works. The catch is it never does work on first time click. That is:

我点击浏览,选择我的文件,preSS上传。什么也没有发生(fupld.HasFile = FALSE);

I click on browse, select my file, press upload. Nothing happens (fupld.HasFile = false);

我再次点击浏览,选择任何文件(相同或不同),preSS上传和正常工作。

I click on browse again, select any file (the same or another), press upload and it works fine.

<asp:UpdatePanel ID="upGeneral" runat="server" >
   <ContentTemplate>
       ...
       <table id="tabPage10" runat="server" visible="false" width="100%" >
          <tr>
              ...
              <td>
                  <asp:FileUpload ID="fupld" runat="server" Width="80%" />
                  <asp:ImageButton ID="ibtnUpld" runat="server" onclick="ibtnUpld_Click" />
              <td>
              ...
          <tr>
       ...
   </ContentTemplate>
   <Triggers>
      <asp:PostBackTrigger ControlID="ibtnUpld" />
   </Triggers>
</asp:UpdatePanel>

我看了看周围的答案,但是这是一些非常怪异的行为。至今没有运气。

I've looked around for answers, but this is some really weird behaviour. No luck so far.

任何想法?

感谢

推荐答案

那么,FileUpload控件设计为只能使用在回发的情况,而不是在部分页面呈现在异步回发的情况。

Well, the FileUpload control is designed to be used only in postback scenarios and not in asynchronous postback scenarios during partial-page rendering.

<一个href=\"http://msdn.microsoft.com/en-us/ysf0192b#using_the_FileUpload_Control_with_the_UpdatePanel_control\" rel=\"nofollow\">http://msdn.microsoft.com/en-us/ysf0192b#using_the_FileUpload_Control_with_the_UpdatePanel_control

您可以使用 AsyncFileUpload 控制,而不是从AjaxControlToolkit。

You could use the AsyncFileUpload control instead from the AjaxControlToolkit.

<asp:AsyncFileUpload runat="server" ID="asyncFileUpload" Width="400px" ThrobberID="imageThrobber"
   OnClientUploadStarted="uploadStarted" OnClientUploadError="uploadError"
   ClientIDMode="AutoID" PersistFile="true" PersistedStoreType="Session" />

背后code:

     if (asyncFileUpload.HasFile)
     {
        string fullPath = GetPath(asyncFileUpload.FileName);
        asyncFileUpload.SaveAs(fullPath);
     }

我从来没有任何问题了。

I've never had any problems with it.

这篇关于文件上传+ UpdatePanel的不首先点击工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆