Forums » .NET » ASP.NET »

How to pass values from page1 to page2 using querystring i need code explanation for the


Posted Date: 15 Oct 2012      Posted By:: naresh Profile photo    Member Level: Silver    Member Rank: 602     Points: 1   Responses: 5




How to pass values from page1 to page2 using querystring

i need code explanation for the above asap




Responses

#691743    Author: Anil Kumar Pandey      Member Level: Diamond      Member Rank: 1     Date: 15/Oct/2012   Rating: 2 out of 52 out of 5     Points: 2

Simply use In page 1


Response.Redirec("page2.aspx?name="+txtName.Text);



in the second page, page load event read value as


txtname.Text = Response.QueryString["name"].ToString();


Thanks & Regards
Anil Kumar Pandey
Microsoft MVP, DNS MVM


 
#691747    Author: SQL Programmers      Member Level: Gold      Member Rank: 172     Date: 15/Oct/2012   Rating: 2 out of 52 out of 5     Points: 4

Hi,

Try like this.

Page1:
private void btnGO_Click(object sender, System.EventArgs e)
{
Response.Redirect("page2name.aspx?Type=Event&EventID=" + txtID.text, false);
}

For Type parameter, Event is the hardcode value.
EventID is the second parameter and it gets value from a textbox.


Second Page: page2name.aspx

private void Page_Load(object sender,System.EventArgs e)
{
if (Request.QueryString["Type"] != null)
txtType.Text = Request.QueryString["Type"];
if (Request.QueryString["EventID"] != null)
txtEventID.Text = Request.QueryString[EventID];
}

SQL Server Programmers and Consultants


 
#691749    Author: Asheej T K        Member Level: Diamond      Member Rank: 2     Date: 15/Oct/2012   Rating: 2 out of 52 out of 5     Points: 4

Hi,

QueryString is used to transfer values from one page to another.

Main advantages of querystring are
1. Simple to use
2. No overload
3. Suports all browsers

Disadvantages,

1. It can transfer the value of maximum 255 characters.
2. Visible to user so cannot used for sensitive data
3. User can tamper the querystring with very less effert.


//TO pass the query string use below code,
Response.Redirect("Testpage.aspx?ID=1")

//To get the query string value use below code,
string QsValue= Request.QueryString["ID"].toString();



Regards,
Asheej T K
Microsoft MVP[ASP.NET/IIS]
DotNetSpider MVM





 
#691752    Author: varalakshmi      Member Level: Bronze      Member Rank: 5218     Date: 15/Oct/2012   Rating: 2 out of 52 out of 5     Points: 2

hi,


In Page1:

Response.Redirect("Page2.aspx?address="+ txtAddress.Text);




In Page2: In page load event call the address

string strAddress = Request["address"].ToString();


Thanks&Regards
Varalakshmi.D


 
#691761    Author: Prasad kulkarni        Member Level: Diamond      Member Rank: 6     Date: 16/Oct/2012   Rating: 2 out of 52 out of 5     Points: 4

As we know HTTP is state less protocol so the values entered by the user are not persist between postback. To save the values we need to use state managment technique like Server side and client side state managment technique.
Query string is one of the statemanagment technique where send some values from one page to another with the help of browser URL/address bar.
The basic syntax is
1. default2.aspx - Pagename to redirect to
2. variables list to be send to another page is separated by comma
3. Question mark sign to be append after page name and variable list


default2.aspx?name=ABC&lastName=XYZ


On Default2.aspx we can get nack this variables with the help of Request.Querystring
check followng code snbippet


if(Request.QueryString["name"] != mull)
String szName = Request.QueryString["name"].toString();


hope it helps

Thanks
Koolprasd2003
Editor, DotNetSpider MVM
Microsoft MVP [ASP.NET/IIS]


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Creating list from textbox as we type in textbox using vb
Previous : Clientscript.registerstartupscript in asp.net
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages

Subscribe to Subscribers
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India