Hi once again
Im trying to use sessions, im passing a value from login page and using it on another page, now i recieve this error "Object reference not set to an instance of an object."

here im passing it
Session["UserName"] = Login1.UserName;

then accessing on different page like this
username = Session["UserName"].ToString();

Please help me on how can i access it.

Recommended Answers

All 2 Replies

Are you sure that the Username in Login1.Username is a string? convert it to string just to be safe.

Test the value before you use it

if (Session["UserName"] != null)
  userName = Convert.ToString(Session["UserName"]);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.