Rex_C Rex_C - 3 months ago 12
ASP.NET (C#) Question

setting up an if else statement to check for a querystring

I'm looking to make an if else statement that does one action if it detects a query string and another action if there isn't one detected. My trouble is in the syntax, I haven't been able to find a good example.

I'm looking for something along the lines of:

if (requisition_id = null)

do this action

else

do this action


I'm basically looking for the syntax needed to identify the querystring, the rest of the code I've got ready for it.

Any help appreciated

Thanks

Answer

To read the value of a query argument, use the QueryString collection of the Request object. If it returns null for the query argument name, then it was not supplied in the URL.

string argname = Request.QueryString["argname"];
if (argname != null)
{
    // argname contains the argument value
}
else
{
    // No argument value was supplied
}