I have a page.aspx that reads the query string, and if the QueryString is something like page.aspx?id=1, it runs some code.
However, I want it to simply ignore that code if no QueryString is specified. If I simply go to page.aspx. Right now, the only code I have on page load is
if (Request.QueryString["id"].Equals("1"))
{
//Do something
}
That works if I go to page.aspx?id=1. However, simply going to page.aspx gives me this error:
object reference not set to an instance of an object
How can I load the page with no query string?
You need to check for nulls
if (Request.QueryString["id"] != null && Request.QueryString["id"].Equals("1"))
{
//Do something
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With