vb.netwebforms

How do I use OnBubbleEvent and RaiseBubbleEvent in ASP.NET?


Microsoft has Control.RaiseBubbleEvent to handle the Control.OnBubbleEvent method.

I have the following VB.NET code in the same ASP.NET WebForm:

<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")>
Protected Overrides Function OnBubbleEvent(source As Object, e As EventArgs) As Boolean
    Dim csrWhere As String = Session("csrWhere").ToString()
    If Not String.IsNullOrEmpty(csrWhere) Then
        Response.Redirect(Request.Url.ToString())
    End If
    Return MyBase.OnBubbleEvent(source, e)
End Function

<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")>
Private Sub Refresh(sender As Object, e As EventArgs)
    RaiseBubbleEvent(Me, EventArgs.Empty)
End Sub

The debugger breakpoint on the Refresh method is called, and RaiseBubbleEvent(Me, EventArgs.Empty) is called, but the breakpoint for the override function OnBubbleEvent is never reached.

What have I done wrong?


Solution

  • I have the following VB.NET code in the same ASP.NET WebForm

    That's your problem. Overriding both methods in a page doesn't make sense. The point is that a child control raises the event and it's handled by a parent. Examples of parent controls given here are Repeater, Datalist and GridView. This is why you should ALWAYS read the relevant documentation. This example is, in part, described thusly:

    The following example overrides the OnBubbleEvent method in a custom ASP.NET server control, ParentControl. This method is invoked when a child control of ParentControl calls the RaiseBubbleEvent method.

    So, a child control calls RaiseBubbleEvent and that invokes OnBubbleEvent in the parent. I'm not sure exactly what you're actually trying to achieve but it doesn't sound like that.