sj1187534
Well-known member
Hi....Can anyone tell me how to load a usercontrol before the actual page that contains the user control is loaded?? I have a usercontrol defines like this in the .aspx.vb page:
Protected WithEvents StateControl As ddlState
========================
and I have the page load function in the main page like this:
========================
Protected Overloads Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyBase.Page_Load()
If Not Page.IsPostBack Then
Dim curUser As User
curUser = New User(Session("username"))
Retrieves all the information into the "curUser" instance of the "User" class
curUser.Retrieve()
StateControl._State() = curUser._State()
........................
........................
End If
End Sub
========================
The error:
========================
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 67: Retrieves all the information into the "curUser" instance of the "User" class
Line 68: curUser.Retrieve()
Line 69: StateControl._State() = curUser._State()
Line 70: lblUsername.Text = Session("username")
Line 71: Load_Label(curUser._Pass())
Source File: W:\Morphic\MSI.Sol\MSI.Web\MSIEditProfile.aspx.vb Line: 69
========================
I have tried many things but everything turned out be futile. I know what the problem is but I am not able to figure out how to fix that.
The Problem:
The Page_Load() method of the .aspx page is loading before the Page_Load() of the user control. So, the "StateControl" is nothing in Line 69 above. I even placed the whole code in the Page_Load() method of the user control in the Page_Init() method. It didnt work wither.
Any help would be really appreciated.
Thanks,
SJ
Protected WithEvents StateControl As ddlState
========================
and I have the page load function in the main page like this:
========================
Protected Overloads Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyBase.Page_Load()
If Not Page.IsPostBack Then
Dim curUser As User
curUser = New User(Session("username"))
Retrieves all the information into the "curUser" instance of the "User" class
curUser.Retrieve()
StateControl._State() = curUser._State()
........................
........................
End If
End Sub
========================
The error:
========================
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 67: Retrieves all the information into the "curUser" instance of the "User" class
Line 68: curUser.Retrieve()
Line 69: StateControl._State() = curUser._State()
Line 70: lblUsername.Text = Session("username")
Line 71: Load_Label(curUser._Pass())
Source File: W:\Morphic\MSI.Sol\MSI.Web\MSIEditProfile.aspx.vb Line: 69
========================
I have tried many things but everything turned out be futile. I know what the problem is but I am not able to figure out how to fix that.
The Problem:
The Page_Load() method of the .aspx page is loading before the Page_Load() of the user control. So, the "StateControl" is nothing in Line 69 above. I even placed the whole code in the Page_Load() method of the user control in the Page_Init() method. It didnt work wither.
Any help would be really appreciated.
Thanks,
SJ