Catching events in web form fired by user control

N

Nick Lewis

I'm trying to process an event raised by a user control in the web
form
that contains that control. I've fathomed out how to handle the event
within the control but how can I then pass it on to the parent web
form?

Thanks,

Nick
 
G

Gary McCormack

You have a couple of ways of doing this. You can either
bubble the even using the RaiseBubbleEvent method in the
user control and overriding the OnBubbleEvent method in
the WebForm, or you can explicitly declare and raise an
event from your user control and catch it in your WebForm.
For example, if you wanted to ripple a Button click...

In UserControl:
....
Public Event SaveClicked(ByVal sender As Object, ByVal e
As System.EventArgs)
....
Private Sub btnSave_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles btnSave.Click
RaiseEvent SaveClicked(sender, e)
End Sub


In WebForm:

Private Sub MyUserControl_SaveClicked(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
MyUserControl.SaveClicked
'Do Something...
End Sub

That should work (although I've just type it from memory,
so there may be some syntax errors or typos...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top