473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Session Var Question

I am developing with VS.NET 2003 on the ASP.NET 1.1 platform.

I don't know how to get around this 'Object reference not set to an instance
of an object' error.

How should I check to see if a session variable exists?
Shouldn't just erifying that the variable does not equal null do the job?

The very first time this page loads, the variable will not exists as it does
not get assigned until the user interacts with a diffrent page.

On a round trip from that other page however, the variable will exist.

As it is now, 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:

Line 90: DDL_BlockList.DataSource =
bizObj.Get_Distinct_Block_Lists(IB_Acct);Line91: DataBind();
Line 92: if(Session["NewList"].ToString() != "")
Line 93: DDL_BlockList.SelectedValue = Session["NewList"].ToString();
Line 94:

Mar 23 '06 #1
2 5649

"Frank" <fk******@pfmail.com> wrote in message
news:eE****************@TK2MSFTNGP10.phx.gbl...
I am developing with VS.NET 2003 on the ASP.NET 1.1 platform.

I don't know how to get around this 'Object reference not set to an
instance of an object' error.

How should I check to see if a session variable exists?
Shouldn't just erifying that the variable does not equal null do the job?

The very first time this page loads, the variable will not exists as it
does not get assigned until the user interacts with a diffrent page.

On a round trip from that other page however, the variable will exist.

As it is now, 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:

Line 90: DDL_BlockList.DataSource =
bizObj.Get_Distinct_Block_Lists(IB_Acct);Line91: DataBind();
Line 92: if(Session["NewList"].ToString() != "")
Line 93: DDL_BlockList.SelectedValue = Session["NewList"].ToString();
Line 94:


In your code line 92 you are calling .ToString() on your session
variable. If it is null then ToString is not available. Try adding a
check for:

if(Session["NewList"] != null) before you check to see if the ToString is
!= "".
Mar 23 '06 #2
Frank,

In the code you're checking for an empty string instead of null.

you should try this first:

if (Session["NewList"] != null && Session["NewList"].ToString() !=
String.Empty)

That if condition will check if it's not null, if that's true it will
continue to check the string.

"Frank" wrote:
I am developing with VS.NET 2003 on the ASP.NET 1.1 platform.

I don't know how to get around this 'Object reference not set to an instance
of an object' error.

How should I check to see if a session variable exists?
Shouldn't just erifying that the variable does not equal null do the job?

The very first time this page loads, the variable will not exists as it does
not get assigned until the user interacts with a diffrent page.

On a round trip from that other page however, the variable will exist.

As it is now, 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:

Line 90: DDL_BlockList.DataSource =
bizObj.Get_Distinct_Block_Lists(IB_Acct);Line91: DataBind();
Line 92: if(Session["NewList"].ToString() != "")
Line 93: DDL_BlockList.SelectedValue = Session["NewList"].ToString();
Line 94:

Mar 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Xizor | last post by:
Let's say I run a server. I have two people using the server. Bill and Joe. Bill is at address.com/bill and Joe is at address.com/joe. Let's say Joe and Bill are both using PHP with sessions on...
1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
3
by: VijayShankar | last post by:
Can u be more specific on your question Anyway its not like Session variables are available for sometime and not available for sometime. When your session starts it is very much available...
1
by: Ernest Forman | last post by:
How can I view the defined Session Variables in the Dotnet environment? I found the session object and it shows me the count of the number of items, but I don't see how to see the names and values...
3
by: Jeff Smythe | last post by:
I simply want to execute some code once when a new session of my ASP.NET application is started (I'm not using session state for anything else - just writing some data to a database). I thought...
4
by: DavidS | last post by:
First: There are several ways to confuse one regarding session timeout. (1) web.config - <sessionState timeout="20"> (2) IIS Manager | Internet Information Services | ServerNode | Default Web Site...
10
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much...
18
by: Rippo | last post by:
Hi I am using role base forms authentication in asp.net and have come across a problem that I would like advice on. On a successful login a session variable is set to identify a user. This is...
5
by: George | last post by:
Hi, Is it possible to delay session creation in ASP.NET I want the user to browse my site without any session created (no cookies set). My pages will know that is Session = null then Session has...
2
by: Kevin Frey | last post by:
Hello, I've been reading that ASP.NET serialises (ie. processes one at a time) HTTP requests if two simultaneous requests need to access the same session state. It also makes note that ASP.NET...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.