The filename does not stay in Fileupload control's textbox, after postback. I've tried using Session object but it still doesnt work.
ASPX: <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:FileUpload ID="fileupload1" runat="server"></asp:FileUpload>
<asp:Button ID="btnUpload" runat="server" Text="Upload Image"
OnClick="btnUpload_Click" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
</asp:UpdatePanel>
CS:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["FileUpload1"] == null && FileUpload1.HasFile)
{
Session["FileUpload1"] = FileUpload1;
}
else if (Session["FileUpload1"] != null && (! FileUpload1.HasFile))
{
FileUpload1 = (FileUpload) Session["FileUpload1"];
}
else if (FileUpload1.HasFile)
{
Session["FileUpload1"] = FileUpload1;
}
}
protected void btnUpload_Click(object sender, EventArgs e)
{
if (fileupload1.HasFile)
{
fileUpload1.SaveAs(Server.MapPath("~/UploadedContent/Temp.jpg"));
img.ImageUrl = "~/UploadedContent/Temp.jpg";
FileUpload1 = (FileUpload) Session["FileUpload1"];
}
}
I am able to preview the image onclick, but the filename does not appear anymore after that, in the fileupload control. How can I achieve this.