Interact with an event in a user control

VBAHole22

Contributor
Joined
Oct 21, 2003
Messages
432
Location
VA
I have a web page in C# 2.0 that i made using studio 05. This page has a user control in it with a button on it. I want the page to be able to tell when the button in the user control is clicked.
Can this be done?
I googled it and found a few conflciting articles about what event bubbling is as opposed to event delegation. All of the sample code I found was for asp.net 1.1
Folks were adding event delegations in the code. Correct me if I'm wrong but that has changed significantly with the partial class code model, hasn't it?

I mean I can't even see my InitializeComponent code can I? Where is the rest of the partial class? Is it created in memory at runtime? If so how can I latch events on?
 
You should be able to handle the click event for the button within the control and then get this to raise an event defined by the control.
The introduction of partial classes should really affect your ability to add an event handler, also rather than declaring a new delegate you could simply use the System.EventHandler if you do need to pass any information or if you do then .Net 2.0 also defines a generic to simplify the declaration (the name of it escapes me at the moment though ;)).
 
I kind of get what you are saying but I can't make it work without seeing it.

I have a button inside my control and I handle the click event of that just fine. But I want my parent page to be able to respond to this as well. Basically I want to hide the control after the button inside of it has been clicked.
So I register an event inside my control like this

Code:
public event EventHandler ReviewSubmitted; //public event
    private void OnReviewSubmitted(object sender, EventArgs e)
    {
        ReviewSubmitted(sender, e);
    }

and after the button inside is done doing its business i call

Code:
OnReviewSubmitted(this, EventArgs.Empty);

That will compile fine but I know i need another piece in the parent aspx page to handle the call to that event.

But when i highlight my user control in design view i get no lightning bolt in the properties so how do i define an event?

I think I'm close i'm just a little clueless.
 
Back
Top