<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中正确工作。问题在于视图2

该文件上传有什么问题?

最佳答案

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

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


也可以看看:

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

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

10-17 01:53