开发者

How do I create a base page event that fires after the derived page's load event?

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 f开发者_C百科irst page loads'

End Sub


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜