Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7530651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:58:07+00:00 2026-05-30T04:58:07+00:00

I’m working on an image gallery, where the user can upload images. The uploaded

  • 0

I’m working on an image gallery, where the user can upload images. The uploaded image is converted to a thumbnail and put in a specific folder for thumbnails, and the original image is put in a folder for full size images.

In Page_Load method in code behind i’m getting the thumbnails from the folder and bind them to the Repeater that i’m using, which means that all images in that folder are displayed when the page is loaded.

When a user chooses to upload an image the UploadButton_Click function is called, the file is processed and then displayed in full size. Everything works fine accept that the uploaded image thumbnail isn’t shown directly after it’s uploaded. To show it you must reload the page, so that Page_Load is loaded again.

Of course, an east way of solving this is to put the code for fetching the thumbnails and binding the Repeater control even in the UploadButton_Click function, but that is DRY which I don’t like.

Is there any better, more elegant way of solving this?

code behind:

 protected void Page_Load(object sender, EventArgs e) {
    var directory = new DirectoryInfo(Gallery.PhysicalApplicationPath + "/Images");
    var theFiles = directory.GetFiles();

    ImageRepeater.DataSource = theFiles;
    ImageRepeater.DataBind();

    var dataName = Request.QueryString["name"];

    if (dataName != null) {
        fullSizeImage.ImageUrl = "Images/" + dataName;
    }
 }

protected void UploadButton_Click1(object sender, EventArgs e) {
    if (Page.IsValid) {
        if (ImageUpload.HasFile) {
            var content = ImageUpload.FileContent;
            var name = ImageUpload.FileName;
            var image = Gallery.SaveImage(content, name);

            fullSizeImage.ImageUrl = "Images/" + image;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:58:08+00:00Added an answer on May 30, 2026 at 4:58 am

    it’s to do with the page lifecycle. The Page_load is firing before the upload happens.

    Try putting the code that populates thumbnails in the Page_PreRender Rather than the Page_Load.

           protected void Page_PreRender(object sender, EventArgs e) {
             //CODE HERE}
    

    That way it will get fired after the upload button click has taken place and not before.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Does anyone know how can I replace this 2 symbol below from the string
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to loop through a bunch of documents I have to put
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.