Catching events in web form fired by user control

  • Thread starter Thread starter Nick Lewis
  • Start date Start date
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
 
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...)
 
Back
Top