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.

1

1 Answer 1

0
Request.QueryString["value"]

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

Sign up to request clarification or add additional context in comments.

3 Comments

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.
Response.Write it is about writing string to HTTP response output stream. Take a look at 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
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.