[英]UpdatePanel in Master Page and FileUpload on Child Page
My updatePanel is in MasterPage and FileUpload is in Child Page. 我的updatePanel在MasterPage中,而FileUpload在子页面中。 As FileUpload requires a full PagePostBack I tried following approaches, but none of them worked, fileupload.hasfile gives false and postedfile is null. 由于FileUpload需要完整的PagePostBack,因此我尝试了以下方法,但没有一个起作用,fileupload.hasfile给出了false,postedfile为null。 Not sure what else to do. 不知道该怎么办。 Please go through and suggest. 请通过并提出建议。 Is there anything that I am missing. 有什么我想念的吗? Using .NET Framework 4.0, Bootstrap 4 使用.NET Framework 4.0 Bootstrap 4
Approach 1 - Adding Postback trigger through code behind 方法1-通过后面的代码添加回发触发器
AddTriggers(btnupload.UniqueID);
public static void AddTriggers(string ControlID)
{
UpdatePanel UP = Page.Master.FindControl("MainUpdPanel") as UpdatePanel;
UpdatePanelControlTrigger trigger = new PostBackTrigger();
trigger.ControlID = ControlID;
UP.Triggers.Add(trigger);
}
Approach 2 - Wrapping fileupload and it's button in a separate UpdatePanel in child Page 方法2-在子页面的单独UpdatePanel中包装文件上传及其按钮
<asp:UpdatePanel ID="Upld" runat="server">
<ContentTemplate>
<div class="input-group form-inline">
<asp:FileUpload ID="FileUploadreq" runat="server" />
<asp:Button runat="server" ID="btnupload" Text="Upload" OnClick="btnupload_Click" />
<asp:LinkButton runat="server" Text="View" ID="lnkview" OnClick="lnkview_Click" Visible="False"></asp:LinkButton>
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnupload" />
</Triggers>
</asp:UpdatePanel>
Add enctype="multipart/form-data"
to the form tag and add the trigger in your page Page_Init function 将enctype="multipart/form-data"
添加到表单标签,并将触发器添加到页面Page_Init函数中
protected void Page_Init(object sender, EventArgs e)
{
AddTriggers(btnupload.UniqueID);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.