Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User Control Events

I have a user control with a button named upload in it. The button click event looks like this:

 protected void btnUpload_Click(object sender, EventArgs e)
{
  // Upload the files to the server
}

On the page where the user control is present, after the user clicks on the upload button I want to perform some operation right after the button click event code is executed in the user control. How do I tap into the click event after it has completed its work?

like image 623
Kumar Avatar asked Feb 22 '10 15:02

Kumar


1 Answers

You have to create an event in your user control, something like:

public event EventHandler ButtonClicked;

and then in your method fire the event...

protected void btnUpload_Click(object sender, EventArgs e)
{
   // Upload the files to the server

   if(ButtonClicked!=null)
      ButtonClicked(this,e);
}

Then you will be able to attach to the ButtonClicked event of your user control.

like image 111
jmservera Avatar answered Oct 06 '22 00:10

jmservera