User Control Events

asp.net, c#, event-handling, user-controls

Solution

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.

Problem

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?

Original source