views:

21

answers:

1

How do I create a new event in a base page class that fires after all derived pages have fired their load events but before any controls fire their load events.

The following code fires the event before the derived page's load event. I want it to fire the event after the derived page's load event but before all control load events:

Base Class:

Public Event FirstLoad(ByVal sender As Object, ByVal e As System.EventArgs)

Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles   Me.Load
    If Not IsPostBack Then
        RaiseEvent FirstLoad(sender, e)
    End If
End Sub

Derived Class:

Private Sub Page_FirstLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.FirstLoad

    'Stuff here happens before controls load but only on first page loads'

End Sub
+1  A: 

I got this behavior to work properly by overriding the base page's OnLoad method and within that call the base's OnLoad method as per usual, then raise the event that you wish to fire after all of the loads have occurred.

Base Class:

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
    MyBase.OnLoad(e)
    If Not IsPostBack Then
        RaiseEvent FirstLoad(sender, e)
    End If
End Sub
Stephen Mesa