Object Error

G

Guest

I've read through the prevoius posts and coudln't find an answer. I'm getting a "Object reference not set to an instance of an object." and can't figure out why. My pageload sub is check for login = true, then cookie to login, then bounce to login page. So I find if the user isn't logged in and there is no cookie I get this error. I have no drop-downs within the "If Not IsPostBack Then". I have dataasbe calls (datareader) to populate the server objects once login in met. I'm also showing or hiding panels once login is met.
Why is this error occuring (my webconfig fiel is fine, etc.)

Error in: http://www.nasba.com/manage/Default.aspx
Error Message: Object reference not set to an instance of an object.
Stack Trace:
at manageaccount.Page_Load() at System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain()

thanx!
 
S

S. Justin Gengo

Chris,

You need to check if the cookie exists before casting it to a value. For
example, if you are casting the cookie contents to a string you need to wrap
that cast in an if then checking if the cookie is not nothing first.

Dim UserId As Int32 = 0
If Not Request.Cookies.Item("UserId") Is Nothing Then
UserId = CType(Request.Cookies.Item("UserId"), Int32)
End If

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Chris said:
I've read through the prevoius posts and coudln't find an answer. I'm
getting a "Object reference not set to an instance of an object." and can't
figure out why. My pageload sub is check for login = true, then cookie to
login, then bounce to login page. So I find if the user isn't logged in and
there is no cookie I get this error. I have no drop-downs within the "If Not
IsPostBack Then". I have dataasbe calls (datareader) to populate the server
objects once login in met. I'm also showing or hiding panels once login is
met.
Why is this error occuring (my webconfig fiel is fine, etc.)

Error in: http://www.nasba.com/manage/Default.aspx
Error Message: Object reference not set to an instance of an object.
Stack Trace:
at manageaccount.Page_Load() at
System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Page.ProcessRequestMain()
 
G

Guest

thanx, I thought I was doing that but made a slight change in the order, which I was already doing in another area, and it worked. thanx for hitting me with a brick and waking me up.
 

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
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top