hey
asp.net 2.0
in the page_load event of a web page I place this code:
NameValueCollection parameters = Request.QueryString;
string username = parameters[0].ToString();
The URL has a querystring, for example like this: Default.aspx?user=newbie
But this code don't get the querystring, the parameters collection gets no
entries from this line "NameValueCollection parameters =
Request.QueryString;"
What am I doing wrong here?
JeffJeff wrote:
> hey
> asp.net 2.0
> in the page_load event of a web page I place this code:
> NameValueCollection parameters = Request.QueryString;
> string username = parameters[0].ToString();
> The URL has a querystring, for example like this: Default.aspx?user=newbie
> But this code don't get the querystring, the parameters collection gets no
> entries from this line "NameValueCollection parameters =
> Request.QueryString;"
> What am I doing wrong here?
> Jeff
string username = Request.QueryString["user"];
Best bet is to access the querystring collection directly. I'm not sure if
it's something that can do like this, as normally a lot of collections are
copied using the CopyTo method, but this is usually done for arrays not
specialized collections.
Your best bet though is to access it directly from the querystring. Also,
don't use positional identifiers to determine a parameter, it's too easy to
change the order that things will appear in so it's best to use the keyname
instead. Also, don't forget to test for null first or else it'll bomb out
when you run into a case where it's an empty value, that's the most common
gatcha when using the querystring.
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199...2006
"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:udZYNHc%23GHA.4472@.TK2MSFTNGP05.phx.gbl...
> hey
> asp.net 2.0
> in the page_load event of a web page I place this code:
> NameValueCollection parameters = Request.QueryString;
> string username = parameters[0].ToString();
> The URL has a querystring, for example like this: Default.aspx?user=newbie
> But this code don't get the querystring, the parameters collection gets no
> entries from this line "NameValueCollection parameters =
> Request.QueryString;"
> What am I doing wrong here?
> Jeff
>
Default.aspx?user=newbie
string username = Request.QueryString["user"]; gives username a NULL
value...
Any more suggestions?
"Simon Rigby" <google@.simonrigby.co.uk> wrote in message
news:1161951708.089584.264150@.m7g2000cwm.googlegroups.com...
> Jeff wrote:
> string username = Request.QueryString["user"];
>
"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:udZYNHc%23GHA.4472@.TK2MSFTNGP05.phx.gbl...
> hey
> asp.net 2.0
> in the page_load event of a web page I place this code:
> NameValueCollection parameters = Request.QueryString;
> string username = parameters[0].ToString();
> The URL has a querystring, for example like this: Default.aspx?user=newbie
> But this code don't get the querystring, the parameters collection gets no
> entries from this line "NameValueCollection parameters =
> Request.QueryString;"
> What am I doing wrong here?
> Jeff
>
I usually use the form
if Request.QueryString.Item("_o") <> string.empty then
stroID = Request.QueryString.Item("_o").tostring()
end if
to get the whole collection you can use
Dim coll As NameValueCollection
coll=request.querystring
and then you can access it using coll("_o") for example
Mike
Monday, March 26, 2012
newbie: Problem getting the querystring!
Labels:
0in,
asp,
codenamevaluecollection,
event,
heyasp,
net,
newbie,
page,
page_load,
parameters,
querystring,
querystringstring,
request,
username,
web
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment