Request.QueryString

G

Guest

Hi,

I have been using VB.Net for the past 2 years and have moved to C#

I send a value in the URL to a page.

In my called page I do below.

int intTest = int.Parse(Request.QueryString["TestID"]);

If this is blank I get an error.

So I decided to check if it was empty by doing a ..

If Request.QueryString["TestID"] = ""
{
....raise an error
}

However it does not like this check.

Why is this? This is what I would do in VB.Net

It seems very simple but I don't know.

I basically want to check if the value being passed in is empty.

Any advice much appreciated.
 
C

Chris R. Timmons

Hi,

I have been using VB.Net for the past 2 years and have moved to C#

I send a value in the URL to a page.

In my called page I do below.

int intTest = int.Parse(Request.QueryString["TestID"]);

If this is blank I get an error.

So I decided to check if it was empty by doing a ..

If Request.QueryString["TestID"] = ""
{
....raise an error
}

However it does not like this check.

Why is this? This is what I would do in VB.Net

It seems very simple but I don't know.

I basically want to check if the value being passed in is empty.

If the query string parameter does not exist, the Request.QueryString
element will be null. That means you have to check for a null value,
not an empty string. Here's how I get query string parameter values:

int intTest;

if (Request.Params["TestID"] == null)
throw ArgumentNullException(...);
else
intTest = int.Parse(Request.Params["TestID"]);
 

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

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top