newbie: How can I retrieve the params placed in URL

J

Jeff

OS: XPpro sp2
IDE: vs .NET 2003

I have URL like this one: http://localhost/index.aspx?carId=volvo . And in
the Page_Load event I want to extract the carId=volvo parameter, so I can do
further processing based on it... As far as I know this parameter can be
found in the Request object, but I haven't solved it yet... Please can some
of you tell me how I can extract the parameter from the URL???

Jeff
 
T

TDAVISJR

Don't forget to do some defensive programming

string carId;
if( Request.QueryString["carId"] != null)
{
carId = (string) Request.QueryString["carId"];
}
else
{
carId = String.Empty;
}
--
TDAVISJR
aka - Tampa.NET Koder


Francisco Padron said:
string carId = Request.QueryString["carId"];

--
Francisco Padron
www.chartfx.com


Jeff said:
OS: XPpro sp2
IDE: vs .NET 2003

I have URL like this one: http://localhost/index.aspx?carId=volvo . And
in the Page_Load event I want to extract the carId=volvo parameter, so I
can do further processing based on it... As far as I know this parameter
can be found in the Request object, but I haven't solved it yet... Please
can some of you tell me how I can extract the parameter from the URL???

Jeff
 
F

Francisco Padron

Just out of curiosity, why you are doing all this ?

string carId = Request.QueryString["carId"];

Will work whether the parameter is there or not, why would you want to
retrieve it twice ? you don't need the casting either,
Request.QueryString["carId"] returns a string not an object.

If you don't want to worry in your code about carId being null, you can add
the line:

if (cardId == null)
cardId = string.Empty;

This will save you one call to QueryString[].

In most cases I prefer to leave it at null and use String.IsNullOrEmpty in
my comparisons, but both options are equally valid in my opinion.

--
Francisco Padron
www.chartfx.com


TDAVISJR said:
Don't forget to do some defensive programming

string carId;
if( Request.QueryString["carId"] != null)
{
carId = (string) Request.QueryString["carId"];
}
else
{
carId = String.Empty;
}
--
TDAVISJR
aka - Tampa.NET Koder


Francisco Padron said:
string carId = Request.QueryString["carId"];

--
Francisco Padron
www.chartfx.com


Jeff said:
OS: XPpro sp2
IDE: vs .NET 2003

I have URL like this one: http://localhost/index.aspx?carId=volvo . And
in the Page_Load event I want to extract the carId=volvo parameter, so I
can do further processing based on it... As far as I know this parameter
can be found in the Request object, but I haven't solved it yet...
Please can some of you tell me how I can extract the parameter from the
URL???

Jeff
 

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,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top