Question

<asp:ScriptManager runat="server" ID="S"></asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="U" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Panel runat="server" ID="U1">
            <asp:Button runat="server" ID="Btnnew" Text="new" OnClick="Btnnew_Click"/>
        </asp:Panel>
        <asp:Panel runat="server" ID="U2">
            <asp:FileUpload runat="server" ID="FU" />
            <asp:Button  runat="server" ID="Btnok" OnClick="Btnok_Click"  Text="ok"/>
        </asp:Panel>
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="btnok" />
    </Triggers>
</asp:UpdatePanel>

and server code is

protected void Page_Load(object sender, EventArgs e)
{
    U1.Visible = true;
    U2.Visible = false;
    U.Update();
}
protected void Btnnew_Click(object sender, EventArgs e)
{
    U1.Visible = false;
    U2.Visible = true;
    U.Update();
}
protected void Btnok_Click(object sender, EventArgs e)
{
    U.Update();
    FU.PostedFile.SaveAs("");
}

but File upload is Null. Nobody can help me!!!

No correct solution

OTHER TIPS

Unfortunately you can't use another container inside UpdatePanel to hold the FileUpload control. But you can do like this:

In the markup:

<asp:ScriptManager runat="server" ID="S"></asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="U" UpdateMode="Conditional">
    <ContentTemplate>
            <asp:Button runat="server" ID="Btnnew" Text="new" OnClick="Btnnew_Click" />
            <asp:FileUpload runat="server" ID="FU" />
            <asp:Button runat="server" ID="Btnok" OnClick="Btnok_Click" Text="ok" />
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="Btnok" />
    </Triggers>
</asp:UpdatePanel>

And change your code to hide/unhide the contols, and to save the file:

protected void Page_Load(object sender, EventArgs e)
{
    Btnnew.Visible = true;
    FU.Visible = false;
    Btnok.Visible = false;
    U.Update();
}
protected void Btnnew_Click(object sender, EventArgs e)
{
    Btnnew.Visible = false;
    FU.Visible = true;
    Btnok.Visible = true;
    U.Update();
}
protected void Btnok_Click(object sender, EventArgs e)
{
    if (FU.HasFile)
    {
        string fileName = FU.FileName;
        FU.SaveAs(Server.MapPath("~/Images/") + fileName);// Assuming you have Images folder in the root
    }
    U.Update();
}

You can use <div> or <table> and with css make them look like a panel if you wish.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top