Home > DeveloperSection > Forums > Problem in passing value from one page to other page in ASP.NET
John Smith

Total Post:101

Points:711
Posted on    September-28-2010 10:08 AM

 C# C# 
Ratings:


 3 Reply(s)
 2047  View(s)
Rate this:
Hi,
Could you please let me know how to pass value from one page to other through Query String as I am new in ASP.NET.
Your help will be appreciated!

Thanks,
John


Amit Singh

Total Post:103

Points:721
Posted on    September-29-2010 9:44 AM

We pass the value from one page to another page by query string, we write the syntax as

1) Response.Redirect("Default.aspx?query=John Smith");

where "query" is query string variable and "John Smith" is the string value for query variable.
Now we access the value on Default.aspx page as

string query=Request.QueryString["query"].toString();

2) we pass the multiple parameter by query string then we write the syntax as

Response.Redirect("Default.aspx?query1=John Smith &query2=krish");

Now we access the value on Default.aspx page as

string query1=Request.QueryString["query1"].toString();
string query2=Request.QueryString["query2"].toString();


or
string query1=Request.QueryString[0].toString();
string query2=Request.QueryString[1].toString();


or
string query1=Request.Params[0].toString();
string query2=Request.Params[1].toString();


3) We pass the any value by query string as

string str="JohnSmith";
Response.Redirect("Default.aspx?query="+str);


And access these value on another page by

string query=Request.QueryString["query"].toString();

Modified On Sep-29-2010 09:46:11 AM

Alex R
Alex R

Total Post:40

Points:280
Posted on    September-29-2010 10:09 AM

If you want to pass value from one page to another using Query string then just add name of query followed by its value.

example

supose you have two pages a.aspx and b.aspx and you want to pass value from a.aspx to b.aspx then instead of just redirecting to page b.aspx, redirect to b.aspx as b.aspx?Name=Haider

Here Name is name of Query String and Haider is value you want to pass.

Now to access this value in b.aspx use

string strName = Request.QueryString["Name"].toString();


John Smith

Total Post:101

Points:711
Posted on    September-30-2010 11:00 AM

thx for your time ..:)

Don't want to miss updates? Please click the below button!

Follow MindStick