Check if query string parameter exists

S

shapper

Hello,

How can I check if a parameter, for example "name", is available in a
QueryString?

I need to create a default value if the parameter is not available.

Thanks,

Miguel
 
S

Siva M

if (Request.QueryString["name"] == null)
{
// Default value
}

You may also use String.IsNullOrEmpty (Request.QueryString["name"]) to check
for both null and empty (name exists in the querystring but no value
specified) and give default value. String.IsNullOrEmpty is avaialble in .NET
2.0


Hello,

How can I check if a parameter, for example "name", is available in a
QueryString?

I need to create a default value if the parameter is not available.

Thanks,

Miguel
 
M

Mark Fitzpatrick

You test to see if it's null. For example, in c# you would do the following

string name = string.Empty;

if(Request.QueryString["name"] != null)
{
name = Request.QueryString["name"].ToString();
}

This creates a string called name, sets it to a default value (in this case
string.Empty), and if the querystring variable exists, set the string to
that variable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top