I use a fileupload control with a show button and URL 'remove photo '. When I press the show button, with help of handler I am able to see the image when it is outside Update Panel. But the page is refreshed. How to avoid it.
If I put the FileUpdate Panel inside Update Panel and when 'Show' button used nothing is displayed, even the path is erased!. In code behind, the PhotoUpload also shows as false!
The following are my codes:
<asp:UpdatePanel ID = "UpdatePanel5" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server"
style="z-index: 1; left: 750px; top: 335px; position: absolute; height: 46px; width: 218px; right: 61px;" />
<asp:Button ID="Button4" runat="server" CausesValidation="False"
onclick="Button4_Click"
style="z-index: 1; left: 755px; top: 272px; position: absolute"
Text="Show" />
<asp:HyperLink ID="HyperLink2" NavigateUrl="~/registration.aspx"
runat="server" font-size="small"
style="z-index: 1; top: 278px; position: absolute; width: 80px; left: 829px;">Remove photo</asp:HyperLink>
</ContentTemplate>
</asp:UpdatePanel>
Code-behind:
protected void Button4_Click(object sender, EventArgs e)
{
if (PhotoUpload.HasFile)
{
Session["ImageBytes"] = PhotoUpload.FileBytes;
ImagePreview.ImageUrl = "~/Handler2.ashx";
}
else
{
}
}
Handler:
public class ImageHandler : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
public void ProcessRequest (HttpContext context) {
if ((context.Session["ImageBytes"]) != null)
{
byte[] image = (byte[])(context.Session["ImageBytes"]);
context.Response.ContentType = "image/JPEG";
context.Response.BinaryWrite(image);
}
}
public bool IsReusable {
get {
return false;
}
}
}
Can anyone help me out the page refreshing problem for FileUpload.