Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
XML
<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:
C#
protected void Button4_Click(object sender, EventArgs e)
    {
        if (PhotoUpload.HasFile)
        {
            Session["ImageBytes"] = PhotoUpload.FileBytes; // .FileBytes;
            ImagePreview.ImageUrl = "~/Handler2.ashx";
        }
        else
        {
        }
    }


Handler:
C#
public class ImageHandler : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{

    public void ProcessRequest (HttpContext context) {
       //Checking whether the imagebytes session variable have anything else not doing anything

        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.
Posted
Updated 17-Dec-12 0:34am
v2
Comments
[no name] 17-Dec-12 5:19am    
use update panel..

XML
just write this in script manager tag.

 
<asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="10000">

using this it'll run continue.
Hope this will help you.
Don't forget to mark this as answer if it helps.
 
Share this answer
 
try using ajax AsyncFileUpload, will work fine....
 
Share this answer
 
 
Share this answer
 
FileUpload control does not work with UpdatePanel. You will have to include a postback trigger in your update panel to achieve this. If you do not want postback, you can show image in a popup window with the help of javascript.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900