繁体   English   中英

更新面板的部分回发后,fileupload的FileName是否为空?

[英]FileName of fileupload is empty after a partial postback of an updatepanel?

我在Updatepanel中有一个FileUpload。

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
<Triggers>
    <asp:PostBackTrigger ControlID="SaveButton" />
</Triggers>
<ContentTemplate>
<cc1:TabContainer CssClass="visoft__tab_xpie7" runat="server" ID="tab" ActiveTabIndex="0" Width="100%" Font-Size="11px">
 <cc1:TabPanel runat="server" HeaderText="اطلاعات پایه" ID="TabPanel1">
     <ContentTemplate>
      <div class="row">
       <span style="width: 100px" class="rowtitle">تصویر </span>
        <asp:FileUpload ID="ImageFileUpload" runat="server"/>
        <asp:ImageButton ID="RemoveImageButton" runat="server" ImageUrl="~/images/delete.png" />
      </div>
      <div class="row">
       <span style="width: 100px" class="rowtitle">Category</span>
       <asp:DropDownList ID="CategoryDropDownList" runat="server" Width="200px" AutoPostBack="True" DataTextField="Name" DataValueField="ID" OnSelectedIndexChanged="CategoryDropDownList_SelectedIndexChanged" />
       <asp:RequiredFieldValidator ID="CategoryRFV" runat="server" ControlToValidate="CategoryDropDownList" ForeColor="Red" ValidationGroup="Save" ErrorMessage="مجموعه را انتخاب کنید." Text="*" />
      </div>
      <div class="row" style="height: 300px">
       <span style="width: 100px" class="rowtitle">توضیحات کامل</span>
       <editor:HtmlEditor Style="float: left" runat="server" Width="600px" ID="DescriptionHtmlEditor" />
       <asp:RequiredFieldValidator Text="*" ID="DescriptionRFV" runat="server" ControlToValidate="DescriptionHtmlEditor" ForeColor="Red" ValidationGroup="Save" ErrorMessage="توضیحات را وارد کنید ." />
       </div>
     </ContentTemplate>
    </cc1:TabPanel>
   </cc1:TabContainer> 
   <div class="row" style="text-align: center">
    <asp:Button ID="SaveButton" class="button" Width="100px" OnClick="SaveButton_Click" runat="server" ValidationGroup="Save" Text="ذخیره" />
   </div>
  </ContentTemplate>
  </asp:UpdatePanel>

当我在部分更新回发更新面板后尝试访问FileUpload FileName属性时,它为空。

我想在onc​​ange事件witj javascrip中获得uploadpanel的Filenme,但我没有得到文件的Fullpath。

 function FileChange()
   {
    var filename = document.getElementById('<%= FileNameUpload.ClientID  %>');
    var file = document.getElementById('fileupload');
    filename.value = file.value;
   }

部分回发后如何获取文件上传的文件名?

在更新面板的部分回发之后,当我尝试访问FileUpload FileName属性时,它为空。

更新面板仅拦截常规表单提交并使用xmlhttp请求执行完整回发 因此,最初在input:file元素上进行的选择已在初始回发中提交,之后您将无法再读取它。 为了证明我在说什么,请尝试在初始回发中读取文件名,您将看到可以。

查看您的代码,似乎您还试图通过编程方式设置fileupload元素的值。 出于安全原因,这都是不可能的-您无法通过Javascript访问用户的硬盘驱动器,也无法确定用户应将哪个文件上传到您的网站。 一旦用户选择了文件并提交了表单,选择就消失了; 用户将不得不自己重新选择文件。

您可以尝试许多技巧,使它们与UpdatePanels一起使用,但是从长远来看,最干净的方法是使用jQuery Ajax来实现,因为您可以完全控制提交的内容,不提交的内容和时间。

我希望这有助于弄清为什么您的方法行不通。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM