5

I'm new to ASP.net, how can I read parameters passed from ASP.net page (http://website.com/index.aspx?id=12&nam=eee).

Any small example will be appreciated, just something for me to start from.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303

4 Answers4

10

Using your sample URL:

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

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

Read about Request.QueryString on MSDN. You probably want to convert the id value to an int.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
RichardOD
  • 28,883
  • 9
  • 61
  • 81
3

For security reasons, be careful with XSS attacks. Please use this library:

http://msdn.microsoft.com/en-us/library/aa973813.aspx

Example:

String Name = AntiXss.HtmlEncode(Request.QueryString["Name"]);
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Efe Kaptan
  • 465
  • 2
  • 11
0

They are available in Request.QueryString. This is a collection of string key/value pairs, that can also be accessed by ordinal index.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
cjk
  • 45,739
  • 9
  • 81
  • 112
0
string st1=Request.QueryString["t1"].ToString();
string st1=Request.QueryString["t1"].ToString();
int a=Convert.ToInt32(st1)+Convert.ToInt32(st2);
Response.Write(a);
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186