簡體   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