gpt4 book ai didi

c# - FileUpload 在多 View 和更新面板中不起作用

转载 作者:行者123 更新时间:2023-11-30 22:40:30 25 4
gpt4 key购买 nike

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
<ContentTemplate>

<asp:MultiView ID="MultiView1" runat="server"
ActiveViewIndex="0">
<asp:View ID="View1" runat="server">
<asp:Button Text="next"
runat="server" onclick="Unnamed1_Click" />
</asp:View>
<asp:View ID="View2" runat="server">
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"
style="width: 56px" />
<asp:FileUpload ID="fileupload2" runat="server" />
</asp:View>
</asp:MultiView>
</ContentTemplate>
</asp:UpdatePanel>

后面的代码是

 protected void Button1_Click(object sender, EventArgs e)
{
if (fileupload2.HasFile)
{
//code..
}
}
protected void Unnamed1_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = 1;
}

当我第一次点击 Button1 上传图片时,fileupload2.HasFile 返回“false”

在不刷新页面的情况下再次尝试上传相同的图片,然后 fileupload2.HasFile 返回“true”

在 View1 中正常工作。问题出在 View 2

上传文件有什么问题?

最佳答案

尝试使用 RegisterPostBackControl 注册按钮控件在页面生命周期的早期:

   protected void Page_Init(object sender, EventArgs e)
{
ScriptManager1.RegisterPostBackControl(Button1);
}

另请参阅:

FileUpload and UpdatePanel: ScriptManager.RegisterPostBackControl works the second time.

关于c# - FileUpload 在多 View 和更新面板中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5164492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com