HttpRequest.Params in C# : Get Value of Key

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

I am attempting to fetch the value of a paramter passed in on the http
request url. Example:

http://localhost.mypage.aspx?ID=12345

In the URL above I am wanting to retrieve the value of the key ID.
When I execute the code below I am getting the entire URL and not just
the value of the key ID. Any suggestions?

string idValue = Request.Params.Get("ID");

Thanks...Kevin
 
Use the querystring
<%
Response.Write(Request.QueryString["ID"]);
// Below line outputs same but works for arrays of same named params
Response.Write(Request.QueryString.GetValues("ID")[0]);
%>

or in VB.NET
<%
Response.Write(Request.QueryString("ID"))
Response.Write(Request.QueryString.GetValues("ID")(0))
%>



--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
 
Just try using

string idValue = Request["ID"] for C#
or
string idValue = Request("ID") for VB.NET

That way you dont have to worry bout whether the param was passed using
query string or as a part of post.

Regards,

Hermit Dave
 
Back
Top