views:

617

answers:

2

I want to have a user control containing a save button.

I want the click event attached to the save button to be handled by the containing page not the user control

Is this possible?

EDIT MORE SPECIFIC

Say I have a page called "Editor Page" and a user control called "Editor Buttons". On the "Editor Buttons" user control I have a save button (which is a web control). I want the Click event of the save button to be handled by the "Editor Page" rather than the user control.

The reason for this is because I want to specify base pages that implement common behaviour.

A: 

Can you be more especific ?

RG
+2  A: 

I will assume that you have the code for the UserControl. If that is the case, you can define a Save event in your user control and have it expose the Click event of the save button, either directly, or by internally setting up an event handler and raise the Save event when the button is clicked. That could look something like this in the UserControl:

public event EventHandler Save;

private void SaveButton_Click(object sender, EventArgs e)
{
    OnSave(e);
}

protected void OnSave(EventArgs e)
{
    // raise the Save event
    EventHandler save = Save;
    if (save != null)
    {
        save(this, e);
    }
}
Fredrik Mörk