newbie: How can I retrieve the params placed in URL

  • Thread starter Thread starter Jeff
  • Start date Start date
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
 
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
 
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
 
Back
Top