Use this space to put some text. Update this text in HTML

468x60 banner ad

Advertise with Us

Powered by Blogger.

Friday 8 April 2016

Object Reference not set to an Instance of an Object in asp.net



In the below code, You got that error because your Session["User_ID "] was null and when you try to return a string representation of that you got the object reference  not set to an instance of an object error. There is difference between .Tostring() and casting Convert.ToString().

if (!Page.IsPostBack)
{          
  ViewState["purid"] = Request.QueryString["User_ID"].ToString();
}







Solution for Object Reference not set to an Instance of an Object in ASP.NET

ToString throw null reference error but Convert.ToString() does not throw null reference error.

if (!Page.IsPostBack)
{
  ViewState["purid"] = Convert.ToString(Request.QueryString["order_no_id"]);
}






No comments :

Post a Comment

Ask a Question?