Object reference error in Querystring value

Posted by Self-Innovator under C# on 11/27/2012 | Points: 10 | Views : 1116 | Status : [Member] | Replies : 2
Hi i am getting an error on obheject reference while assigning the querystrning value
protected void Page_Load(object sender, EventArgs e)
{
CustId = string.Empty;
if (!Page.IsPostBack)
{
if (Request.QueryString != null)
{
CustId = Request.QueryString["Id"].ToString();
}
if (chkContactDetails.SelectedIndex != -1)
{
GetContactDetails(CustId);
}
}
}

Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Sandhyab on: 11/27/2012 [Member] Starter | Points: 25

Up
0
Down
Try this,
protected void Page_Load(object sender, EventArgs e)

{
if (!IsPostBack)
{
if (!string.IsNullOrWhiteSpace(Request.QueryString["Id"]))
{
int CustId =int.Parse(Request.QueryString["Id"]);
if (chkContactDetails.SelectedIndex != -1)
{
GetContactDetails(CustId);
}
}
}
}


Thanks & Regards

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabu_Spark on: 11/27/2012 [Member] Starter | Points: 25

Up
0
Down
Hi friend,
You use try, catch statement to handle the exception.

protected void Page_Load(object sender, EventArgs e)
{
CustId = string.Empty;
if (!Page.IsPostBack)
{
try
{
if (Request.QueryString != null)
{
CustId = Request.QueryString["Id"].ToString();
}
if (chkContactDetails.SelectedIndex != -1)
{
GetContactDetails(CustId);
}
}
catch
{
}
}
}

With regards,
J.Prabu.
[Email:prbspark@gmail.com]

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response