Предупреждение: это сообщение "работает на моей машине", а не решение для копирования и вставки любым способом.
Я полагаю, вы видели официальную документацию о совместимости FileUpload
и UpdatePanel
:
Когда вы используете элемент управления FileUpload внутри элемента управления UpdatePanel, файл должен быть загружен с помощью элемента управления, который является объектом PostBackTrigger для панели.
Глядя на ваш код, кажется, что вы уже правильно выполнили эту часть. В вашем контексте директива MasterType
также, похоже, не имеет никакого значения - она добавляет правильно набранное свойство Master
на вашу страницу (в противном случае вы получаете предка MasterPage
и вам необходимо привести его вручную), которое вы похоже, здесь не используется.
Я создал проект fre sh WebForms (. net 4.7.2) и применил ваши биты кода:
CustomMaster.master
<%@ Master Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder id="HeaderContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<h1>Custom Master</h1>
<form id="form1" runat="server">
<asp:ScriptManager runat="server">
<Scripts>
<%--Framework Scripts--%>
<asp:ScriptReference Name="MsAjaxBundle" />
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="bootstrap" />
<asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
<asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
<asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
<asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
<asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
<asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
<asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
<asp:ScriptReference Name="WebFormsBundle" />
<%--Site Scripts--%>
</Scripts>
</asp:ScriptManager>
<asp:ContentPlaceHolder id="MainContent" runat="server"></asp:ContentPlaceHolder>
</form>
</body>
</html>
Test.aspx
<%@MasterType VirtualPath="CustomMaster.master" %>
<%@ Page Language="C#" MasterPageFile="CustomMaster.master" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="WebApplication4.Test" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<asp:Panel ID="panel_Actions" runat="server">
<asp:UpdatePanel ID="upanel_Actions" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Button ID="btn_downloadEmpTemplate" runat="server" OnClick="btn_downloadEmpTemplate_Click" Text="Download Template"/>
<asp:FileUpload runat="server" ID="fu_excelUpload" />
<asp:Button ID="btn_uploadSubmit" runat="server" OnClick="btn_UploadSubmit_Click" Text="Upload"/>
<asp:Label ID="lbl_filename" runat="server"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btn_uploadSubmit" />
</Triggers>
</asp:UpdatePanel>
</asp:Panel>
</asp:Content>
Test.aspx.cs
using System;
using System.Web.UI;
namespace WebApplication4
{
public partial class Test : Page
{
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.GetCurrent(this).RegisterPostBackControl(this.btn_uploadSubmit);
}
protected void btn_UploadSubmit_Click(object sender, EventArgs e)
{
lbl_filename.Text = this.fu_excelUpload.FileName;
}
protected void btn_downloadEmpTemplate_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
}
}
Насколько я могу судить - комбо работает должным образом, поэтому я бы предложил вам нужно просмотреть действительный код и посмотреть, не является ли что-то другим (файлы в Scripts/WebForms
могут быть), или добавить больше кода к вашему вопросу.