Transfer information between two pages

Source: Internet
Author: User
There are three methods to pass values between different pages in Asp.net:
(1) querystring
Method: Create an Asp.net website (sender) in vs2005, add a button, two Textbox, Code As follows: Protected   Void Button#click ( Object Sender, eventargs E)
{
String URL;
URL =   " Http: // localhost/look1/default. aspx? Name = "   + Textbox1.text +   " & Email = "   + Textbox2.text;
Response. Redirect (URL );
}

Create the acceptor page and add two textbox on the page. The Code is as follows:Textbox1.text=Request. querystring ["Name"];
Textbox2.text=Request. querystring ["Email"];

(2) Use session Variables Private   Void Button#click
( Object Sender, system. eventargs E)
{
Session ["Name"]=Textbox1.text;
Session ["Email"]=Textbox2.text;
Server. Transfer ("Http: // localhost/look1/default. aspx");
}
Target Page code:
Private   Void Page_load
( Object Sender, system. eventargs E)
{< br> textbox1.text = session [ " name " ]. tostring ();
textbox2.text = session [ " email " ]. tostring ();
session. remove ( " name " );
session. remove ( " email " );
}

(3) Use server. Transfer Source Page code:
Add the following code to the page
Public   String Name
{
Get
{
ReturnTextbox1.text;
}
}

Public   String Email
{
Get
{
ReturnTextbox2.text;
}
}
Then call the server. Transfer Method
Private   Void Button#click
( Object Sender, system. eventargs E)
{
Server. Transfer ("Anotherwebform. aspx");
}
Target Page code:
Private   Void Page_load
( Object Sender, system. eventargs E)
{
Webform1 WF1;
WF1=(Webform1) Context. Handler;
Textbox1.text=Wf1.name;
Textbox2.text=Wf1.email;
}

Of course, it is easier to pass values between different pages in the same solution. You only need to change the URL to the page name (for example, default2.aspx! Try it

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.