Passing and using parameters

T

Tor Inge Rislaa

Passing and using parameters



How to get hold of the parameter value provided by the URL? When I open a
web form with a DataSource I often include a parameter in the URL as below:



myNewPage.aspx?myParam = 10



If I simply need to use the value of myParam in the VB code when the new
page load, how do I refer to the parameter?



e.g. myLabel.Text = myParam (where myParam is replaced with a proper way to
refer to it)



TIRislaa
 
M

Mark Fitzpatrick

It comes from the Request.QueryString collection. I forget the VB code, but
in C# it's:

Request.QueryString["myParam"].ToString()

Keep in mind, before you ever attempt to reference it, you'll need to make
sure that it is not a null value. If you don't test for null first, and the
querystring variable isn't present (it could be there but misspelled for
example) then it will through a null reference error when you attempt to use
the ToString() method on it. Always test for null first just in case.

in C# the test woud be:

if(Request.QueryString["myParam"] != null)


--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
 
T

Tor Inge Rislaa

Solved my problem.
Thank you very much!

TIRislaa



Mark Fitzpatrick said:
It comes from the Request.QueryString collection. I forget the VB code,
but in C# it's:

Request.QueryString["myParam"].ToString()

Keep in mind, before you ever attempt to reference it, you'll need to make
sure that it is not a null value. If you don't test for null first, and
the querystring variable isn't present (it could be there but misspelled
for example) then it will through a null reference error when you attempt
to use the ToString() method on it. Always test for null first just in
case.

in C# the test woud be:

if(Request.QueryString["myParam"] != null)


--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006


--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006



Tor Inge Rislaa said:
Passing and using parameters



How to get hold of the parameter value provided by the URL? When I open a
web form with a DataSource I often include a parameter in the URL as
below:



myNewPage.aspx?myParam = 10



If I simply need to use the value of myParam in the VB code when the new
page load, how do I refer to the parameter?



e.g. myLabel.Text = myParam (where myParam is replaced with a proper way
to refer to it)



TIRislaa
 

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,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top