views:

1438

answers:

4

I am trying to aid another programmer with a page called Default.aspx with a code-behind section, and unfortunately I am at a bit of a loss.

 Partial Class _Default
 Inherits OverheadClass
 'A bunch of global variables here'

 Private Sub page_load(ByVal sender As Object, ByVal e As System.Eventarts) Handles Me.Load
 'Function goes here'

And in the OverheadClass we have

 Public Sub Sub_OverheadClass_Load(ByVal sender As Object, ByVal e as System.EventArgs) Handles MyClass.Load

The desired effect is when the OverheadClass is inherited, we want its load to run before the load event on the page runs. There is probably a very simple answer to this that I am missing.

Edit: I forgot to note that we write in VB, and not C# as many of you are used to for ASP.

+11  A: 

You should be able to override the OnLoad and call the base class's OnLoad first, then your class, for example:

C# Version

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);

    // Do some stuff here
}

VB Version

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)

    MyBase.OnLoad(e)

    ' Do some stuff here

End Sub
mattruma
This is absolutely the right answer, as _Default.page_load doesn't override OverheadClass.Sub_OverheadClass_Load. Another option might be to have OverheadClass.Sub_OverheadClass_Load re-raise the event, but I think that would cause NASTY side effects.
John Rudy
The guy is coding in VB. Try to stay in VB ;)
Maxim
@Maxim Good point!
mattruma
+3  A: 

In VB it would be:

Private Sub page_load(ByVal sender As Object, ByVal e As System.Eventarts) Handles Me.Load
  Mybase.Sub_OverheadClass_Load(e)
End Sub
Brian Schmitt
A: 

Your default page should inherit OverheadClass

   Partial Public Class _Default
        Inherits OverheadClass

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            'Do some page stuff'
        End Sub
    End Class

And OverheadClass should inherit System.Web.UI.Page

Public Class OverheadClass
    Inherits System.Web.UI.Page
    Public Sub Sub_OverheadClass_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyClass.Load
        'Do some base stuff'
    End Sub
End Class
Loscas
A: 
 Partial Class OverheadClass
    Inherits System.Web.UI.Page

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) 
       MyBase.OnLoad(e)
    End Sub
End Class



Partial Class _Default
    Inherits OverheadClass

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) 
       MyBase.OnLoad(e)
    End Sub
End Class
Mark Cidade