D
dickson.matt
OK, I have created a user control that contains a dropdown for office
locations.
Here is the code....
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
If Cache("DsOffice") Is Nothing Then
daData.Fill(DsOffice, "spDpCodesOffice")
Cache("DsOffice") = DsOffice
ddOffice.DataSource = Cache("DsOffice")
Else
ddOffice.DataSource = Cache("DsOffice")
End If
ddOffice.DataBind()
End If
End Sub
Public Property SelectedValue()
Get
Return ddOffice.SelectedValue
End Get
Set(ByVal Value)
ddOffice.SelectedValue = Value
End Set
End Property
I have placed the user control on my page....the control loads fine and
I set it's dropdown value to the current value from my DB when I first
load the page.
But when I refresh the page I get...
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:
Office1.SelectedValue = Session("Office")
I placed a watch on the session variable and it does exist and has a
good value .
Here is the entire code for the page containing the control...I tried
moving the code that sets the selected value to the pre_render event of
the page but still got the same error...
Public Class Users
Inherits System.Web.UI.Page
Protected Office1 As SecurityLink.office
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
'Retrieve page data
daData.SelectCommand.Connection = connSQL
daData.SelectCommand.Parameters("@intUserId").Value = 1
daData.Fill(DsUser1, "spDpUser")
'Set session variable values for later use
Session("Office") = DsUser1.Tables(0).Rows(0)("office")
Page.DataBind()
'Select the correct value for the user from the dropdowns
Office1.SelectedValue = Session("Office")
End If
End Sub
locations.
Here is the code....
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
If Cache("DsOffice") Is Nothing Then
daData.Fill(DsOffice, "spDpCodesOffice")
Cache("DsOffice") = DsOffice
ddOffice.DataSource = Cache("DsOffice")
Else
ddOffice.DataSource = Cache("DsOffice")
End If
ddOffice.DataBind()
End If
End Sub
Public Property SelectedValue()
Get
Return ddOffice.SelectedValue
End Get
Set(ByVal Value)
ddOffice.SelectedValue = Value
End Set
End Property
I have placed the user control on my page....the control loads fine and
I set it's dropdown value to the current value from my DB when I first
load the page.
But when I refresh the page I get...
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:
Office1.SelectedValue = Session("Office")
I placed a watch on the session variable and it does exist and has a
good value .
Here is the entire code for the page containing the control...I tried
moving the code that sets the selected value to the pre_render event of
the page but still got the same error...
Public Class Users
Inherits System.Web.UI.Page
Protected Office1 As SecurityLink.office
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
'Retrieve page data
daData.SelectCommand.Connection = connSQL
daData.SelectCommand.Parameters("@intUserId").Value = 1
daData.Fill(DsUser1, "spDpUser")
'Set session variable values for later use
Session("Office") = DsUser1.Tables(0).Rows(0)("office")
Page.DataBind()
'Select the correct value for the user from the dropdowns
Office1.SelectedValue = Session("Office")
End If
End Sub