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

  • Home
  • SEARCH
  • 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 6007483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:41:14+00:00 2026-05-23T01:41:14+00:00

I have a problem while writting event for ImageUpload User control. I want to

  • 0

I have a problem while writting event for ImageUpload User control.

I want to add a event that fire on imagebutton click in this case that green ok button. I write some code for event but it get raised on pageload() and on postback, so it causes a problem –> Image path which is provided for image upload is get clear after image upload but on a page refresh a same image is upload again and again on every page refresh.

User Control Code

public partial class Gallery_Controls_ImgUpload : System.Web.UI.UserControl
{    
  protected void Page_Load(object sender, EventArgs e)
  { }

   public string TxtDesc    
    {        
       get {return txtimgdesc.Text;}        
       set { txtimgdesc.Text = value; }
    }    
    public string TxtImgName    
    {        
       get { return txtimgname.Text; }        
       set { txtimgname.Text = value; }    
    }    
    public FileUpload ImgUpld    
    {        
       get { return ImgUpload; }        
       //set { ImgUpload = value; }    
    }    
    public string ImgAttr    
    {        
       get { return ImgUpload.Attributes["onchange"]; }        
       set { ImgUpload.Attributes["onchange"] = value; }    
    }    

    public event EventHandler ImgBtnUpClick;    
    protected void imgbtnok_Click(object sender,EventArgs e)    
     {        
        ImgBtnUpClick(ImgUpload, e);    
     }

Code for Adding control in page and upload a file

public partial class Gallery_iupload : System.Web.UI.Page
{    
    ASP.gallery_controls_imgupload_ascx upctrl;

    protected void Page_Load(object sender, EventArgs e)    
    {
           upctrl = (ASP.gallery_controls_imgupload_ascx)LoadControl ("Controls/ImgUpload.ascx");
           upctrl.ImgBtnUpClick += new EventHandler(Upload);
           upctrl.ImgAttr = "checkFileExtension(this); return false;"; 
           PlaceHolderupctrl.Controls.Add(upctrl);                    
    }
    protected void Upload(object sender, EventArgs e)
    {        
        TextBox txtbximgname = (TextBox)upctrl.FindControl("txtimgname");
        TextBox txtbxdesc = (TextBox)upctrl.FindControl("txtimgdesc");
        FileUpload Imgload = (FileUpload)sender;
        if (Imgload.HasFile)
            try{
                Imgload.SaveAs("C:\\Uploads\\" + txtbximgname.Text + ".jpg");                   
                Label1.Text = "File name: " + Imgload.PostedFile.FileName + "<br>" +
                Imgload.PostedFile.ContentLength + " kb<br>" +"Content type: " +
                Imgload.PostedFile.ContentType;
                }
            catch (Exception ex)
            {
                Label1.Text = "ERROR: " + ex.Message.ToString();
            }
        else
        {
            Label1.Text = "You have not specified a file.";
        }
    }
}
  • 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-23T01:41:15+00:00Added an answer on May 23, 2026 at 1:41 am

    you have to put a IsPostBack check in your page_load:

     protected void Page_Load(object sender, EventArgs e)        
    {           
        if (!Page.IsPostBack)
        {   upctrl = (ASP.gallery_controls_imgupload_ascx)LoadControl ("Controls/ImgUpload.ascx");               
            upctrl.ImgBtnUpClick += new EventHandler(Upload);           
            upctrl.ImgAttr = "checkFileExtension(this); return false;";            
            PlaceHolderupctrl.Controls.Add(upctrl);      
        }                  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very specific problem. I have a user control (code below) That
I've been thinking about this problem for a while and have yet to come
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
While simple, interface-driven event notification frameworks in Java have been around since pre-Cambrian times
I have this problem and it's drivin' me nuts! So I am developing my
Basically my problem stems from a desire to have the textbox portion be white,
While trying to use LINQ to SQL I encountered several problems. I have table
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am

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.