Hi Wagner,
I think you misread or misunderstood some of the text you quoted:
Quote:
|
quote:You should not include event handlers for controls within a User Control in the page that is hosting the User Control
|
This doesn't say that you cannot handle events from the User Control in the page; all this says is that you shouldn't include handlers for
controls within a user control in the page.
So, say you have a User Control called MemberDetails that allows you to create or update information about a Member. Such a control can have a text box for the name, a text box for the e-mail address and a save button.
The UserName_Change event and the SaveButton_Click event should be handled *inside* the control (that's what the you quoted text is all about). That is because the User Control knows it has a text box called UserName and a button called SaveButton.
However, and this is what Peter is suggesting, you can fire events from within the control that bubble up to the page.
For example, you may want to fire a event like MemberDetailsUpdated. When you save the Member details in the User Control, you can invoke this event.
A page that consumes this User Control can register for this event, and when the Member Details have been saved, a label can be updated, the user can be redirected to another page, or whatever it is you want to do when the details are saved.
In addition, you can bubble up the event for a specific control directly to the parent page. In that case, the parent page can handle the SaveButton_Click event. The code Peter posted does exactly that. Notice that you aren't handling the SaveButton_Click directly; the UC intercepts the event, and then invokes its own public event called SaveClicked.
So, there is a clear distinction between handling the events for controls within the user control, and other public events you define yourself in the UC and that can be handled by the parent page.
Does this make any sense??
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to:
Babylon by
The Tea Party (Track 8 from the album:
Transmission)
What's This?