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
  • 155,156
  • 41
  • 207
  • 295

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
  • 155,156
  • 41
  • 207
  • 295
RichardOD
  • 28,399
  • 8
  • 58
  • 78
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
  • 155,156
  • 41
  • 207
  • 295
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
  • 155,156
  • 41
  • 207
  • 295
cjk
  • 44,524
  • 9
  • 79
  • 111
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
  • 92,042
  • 19
  • 143
  • 183