0
int ob=0;

protected void Button1_Click(object sender, EventArgs e)

{
    ob = Convert.ToInt32(Request.QueryString["value"].ToString());

    if (RadioButton1.Checked == true)
    {
        ob = ob + 1;
    }
    else
    {
        ob = ob + 0;
    }
    Response.Redirect("result.aspx?value = " + ob);
}

exception:- System.NullReferenceException: 'Object reference not set to an instance of an object.'

System.Collections.Specialized.NameValueCollection.this[string].get returned null.

Nithin
  • 1,270
  • 10
  • 28
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – VDWWD Jun 29 '17 at 13:27

1 Answers1

0
Request.QueryString["value"]

It returns null. So when you call ToString() on null it rises exception.

  • In the preceeding page, I have written the following code: Response.Write("ques2.aspx?value =" + ob); so the variable "value" is carried on to this page. – shelovestocode Jun 29 '17 at 13:36
  • Response.Write it is about writing string to HTTP response output stream. Take a look at https://msdn.microsoft.com/en-us/library/1463ysyw(v=vs.110).aspx So in short words even if you call Response.Write("ques2.aspx?value =" + ob); it does not mean that 'value' exists within Request.QueryString – Aleksey Shevchenko Jun 29 '17 at 13:41
  • You should ensure that you pass value parameter from the previous page. E.g. on previous page in code behind you need to call Response.Redirect("your-page.aspx?value=" + "value of value parameter"); In such case on the target page your code - ob = Convert.ToInt32(Request.QueryString["value"].ToString()); will work fine. And of course "value of value parameter" should be an integer. – Aleksey Shevchenko Jun 29 '17 at 13:59