.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Post New Resource Bookmark and Share   

Retain fileupload control after postback

Posted By:abhays       Posted Date: September 26, 2014    Points: 40    Category:    URL: http://www.dotnetspark.com  

Below code snippets explains how to retain fileupload control after postback
 


protected void Page_Load(object sender, EventArgs e)

    {

         if (Session["fileUpload"] == null && fileUploadImage.HasFile)  

           { 

            Session["fileUpload"] = fileUploadImage;

           }         

        else if (Session["fileUpload"] != null && (! fileUploadImage.HasFile)) 

          { 

            fileUploadImage = (FileUpload) Session["fileUpload"]; 

          } 

        else if (fileUploadImage.HasFile) 

         { 

            Session["fileUpload"] = fileUploadImage;

         }

     }



protected void btnUpload_Click(object sender, EventArgs e)

     {

        if (fileUploadImage.HasFile)

        {                

            fileUploadImage.SaveAs(Server.MapPath("~/Images/World.jpg"));

            img.ImageUrl = "~/Images/World.jpg";

            fileUploadImage = (FileUpload) Session["fileUpload"]; 

        }

     }


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend