Page Refresh

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top