| Author: ChandraShekar Thota 18 Jul 2008 | Member Level: Diamond | Rating: Points: 6 |
There are several methods to pass values from one page to another page. Described below are few methods to pass values between pages:
QueryString - The QueryString method of passing values between web pages is one of the oldest methods of passing values between pages. A variable value is properly encoded before it is placed on a querystring. This is to make sure that characters that cause problems (like symbols and spaces) are encoded correctly. See the code below to see how QueryString functionality works.
//Code in InitialPage.aspx String sString; sString = Server.UrlEncode("string in InitialPage.aspx"); Response.Redirect("DestinationPage.aspx?Value=" & sString);
//Code in DestinationPage.aspx reads the QueryString String sString; sString = Request.QueryString("Value"); Response.Write("Your name is " & sString);
The data in the DestinationPage.aspx in the URL looks like this...
Context - The context object is used to send values between pages. Its similar to the session object, the difference being that, the Context object goes out of scope when the page is sent to a browser. Example code below shows how to use Context object.
'InitialPage.aspx stores value in context before sending it Context.Items("MyData") = "dotnetuncle"; Server.Transfer("DestinationPage.aspx");
'DestinationPage.aspx retrieves the value from InitialPage.aspx's context String sString; sString = Context.Items("MyDate").ToString; Response.Write("The data is as follows: " & sString);
Session - The session object is used to persist data across a user session during the user's visit to a website. It is almost same as the Context object. When we use Response.Redirect, it causes the Context object to go away, so rather the Session object is used in such a scenario. Session object uses more of server memory than a context object. Example code below shows how to use Session object.
'InitialPage.aspx stores value in session before sending it Session.Items("MyData") = "dotnetuncle"; Response.Redirect("DestinationPage.aspx");
'DestinationPage.aspx retrieves the value from InitialPage.aspx's session String sString; sString = Session.Items("MyDate").ToString; Response.Write("The data is as follows: " & sString);
You may notice above, I have used Response.Redirect with session object, and server.transfer with a context object.
|
| Author: Kumar Velu 18 Jul 2008 | Member Level: Diamond | Rating: Points: 6 |
Whenever you want to navigate user to some another page on same site or across sites Response.Redirect is used. ASP developers have used Response.Redirect since the days of ASP 1.0 to redirect the browser to another page. Perhaps, everybody thinks that this all occurs on the server and is thus a fairly efficient operation, but that's not how it works. When the ASP.Net engine encounters a Response.Redirect method, it stops the processing of the current page and sends an HTTP redirection header (302 Redirect) to the client, informing it that the page it requested has moved and can be found at a different URL. When this response is sent to the browser, the browser requests the new URL and the ASP engine sends the new page to the client. Thus, the redirection of a page using Response.Redirect requires an extra client/server round trip.
The page URL change with a Response.Redirect unlike Server.Transfer .
//Code in InitialPage.aspx string strName; strName = txtName.Text.ToString(); Response.Redirect("DestinationPage.aspx?Name=" & strName);
//Code in DestinationPage.aspx reads the QueryString String strName; strName= Request.QueryString("Name"); Response.Write("Your name is " & strName);
|
| Author: Yuvaraj 19 Jul 2008 | Member Level: Silver | Rating: Points: 6 |
hi,
There are many methods to pass a value from one page to another page.
One by using session in first web form session["id"] = Textbox1.Text; In second web page Textbox2.Text = session["id"].Tostring();
Second Method by using querystring in first page response.redirect("nextpage.aspx?id=' " +Textbox1.Text+ " ' " ); In second page get the values as string a = Request.QueryString["id"].Tostring();
Third Method by Using Server.Transfer
in First page
Server.Transfer("Firstpage.aspx")
In second page get the values as string a = Request.Form("TextBox1.Text").Tostring()
|
| Author: vasanthiraajan 19 Jul 2008 | Member Level: Gold | Rating: Points: 5 |
hi
1.Session in first web form session["id"] = Textbox1.Text; In second web page Textbox2.Text = session["id"].Tostring();
2.Querystring
in first page response.redirect("nextpage.aspx?id=' " +Textbox1.Text+ " ' " ); In second page get the values as string a = Request.QueryString["id"].Tostring();
3.Server.Transfer
in First page
Server.Transfer("Firstpage.aspx")
In second page get the values as string a = Request.Form[TextBox1.Text"].Tostring()
|
| Author: UltimateRengan 04 Sep 2008 | Member Level: Diamond | Rating: Points: 5 |
hi, Session is used to store the some information to it.you can reuse it another page or site with in project.
for ex:- Set session:- session("UserName")="Rengan" Get session value:- textbox1.text=Session("UserName")
Method Description
Abandon :Destroys a user session Contents: Remove Deletes an item from the Contents collection Contents. RemoveAll() Deletes all items from the Contents collection
Events :-
Session_OnEnd :-
Occurs when a session ends Session_OnStart:-
Occurs when a session starts
|