Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I made a dynamic website but always getting such error like object reference is not set to an instance of an object . I don't understand from where these error come..I am using session to get value.. Please help me..

What I have tried:

lblSales.Text = Session["adminhome"].ToString();
Posted
Updated 14-Jan-18 18:41pm

Easy. You're code is assuming that something is returned by Session["adminhome"] when nothing, null, was returned. You can't call .ToString() on a null object.

The thing you have to do now is figure out why is there nothing being returned by the call to Session["adminhome"]. Either you have to handle the case where that session value may be null or figure out why that value isn't being set in the first place when you expect it to be set.
 
Share this answer
 
Comments
ADI@345 15-Jan-18 0:07am    
Actually what happen, my code work fine on my PC, but if run on another PC,i face this error not always , but sometime..Initially session is not null, i send name and email in session.
Dave Kreskowiak 15-Jan-18 0:57am    
That doesn't change my answer. From what you posted, what I said is all that can be said. There is no way for anyone but you to figure out why it's returning null.

We simply don't have anywhere enough information and code to go on. The quality of the answer you get in a forum is directly dictated by the quality of the question you ask.
You are getting the session value null..
please validate session value before assigning it..

if(Session["adminhome"] != null)
{
  lblSales.Text = Session["adminhome"].ToString();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900