Search code examples
c#asp.netrequest.querystring

redirecting to another asp.net page using request.querystring in asp.net


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.


Solution

  • Request.QueryString["value"]
    

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