Retrieve values from Custom Base Page Class through a User Control
Posted on 2005-04-18
I am building an ASP.NET application that uses a custom BasePage Class for all .aspx pages. Every time the page is loaded, it retrieves an object from Session State and stores it in a private variable. It has a Public Property that allows the controls to access this object.
Public MustInherit Class BasePage
Private objUser As CustomObject
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
'Try to return the CustomObject from the Session
objUser = CType(Session("CustomObject"), CustomObject)
objUser = New CustomObject()
' Call the base OnLoad method
Public ReadOnly Property CustomObject() As CustomObject
When trying to access the public property from a UserControl, I get an object reference error because the User control cannot retrieve the information from the BasePage object because it doesn't know it exists as a BasePage, only as a Page object.
If CType(Page, BasePage).CustomObject.CustomObjectProperty Then
How can I create a custom BaseUserControl class that can reference the BasePage class reference the CustomObject Property?