Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I have simple piece of code which has error showing object reference has not set

What I have tried:

C#
lbltime.Text = DateTime.Now.ToString("hh:mm tt");
                lblusername.Text = Session["username"].ToString();
Posted
Updated 6-Feb-17 2:48am
Comments
[no name] 6-Feb-17 8:15am    
Okay... and? The cause of the problem is the same as everyone else in the universe and you fix it the exact same way as everyone else.

The Session value for "username" is null or the "username" key is not present
try like this
lblusername.Text = Convert.ToString(Session["username"]);
 
Share this answer
 
v2
Very likely, there is NO "username" entry in your Session variable Keys.
 
Share this answer
 
Comments
Member 12605293 6-Feb-17 8:33am    
Hi pallini
Can You show a sample code
Since you ask for example:
Session["username"] = "Donald Trump";
lblusername.Text = Session["username"].ToString();
 
Share this answer
 
v2

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



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