Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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; // .FileBytes;
            ImagePreview.ImageUrl = "~/Handler2.ashx";
        }
        else
        {
        }
    }

Handler:
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 17-Dec-12 0:09am
Edited 17-Dec-12 1:34am
v2
Comments
Krunal Rohit at 17-Dec-12 5:19am
   
use update panel..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

try using ajax AsyncFileUpload, will work fine....
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
0 Maciej Los 184
1 Sergey Alexandrovich Kryukov 154
2 Sascha Lefévre 120
3 Abhinav S 104
4 Jörgen Andersson 75
0 Sergey Alexandrovich Kryukov 6,628
1 OriginalGriff 6,298
2 Peter Leow 2,534
3 Maciej Los 2,437
4 Abhinav S 2,378


Advertise | Privacy | Mobile
Web03 | 2.8.150414.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100