ASP. NET lists page transfer values implemented by nine methods

Source: Internet
Author: User

Method 1

Pass through URL link address

Send. aspx: protected void button#click (object sender, EventArgs e) {Request. Redirect ("Default2.aspx? Username = honge ");} receive. aspx: string username = Request. QueryString [" username "]; To obtain the parameter value.

Method 2:

Post.

send.aspxreceive.aspxstring username = Ruquest.Form["receive"];

Method 3:

Through session

Send. aspx: protected void button#click (object sender, EventArgs e) {Session ["username"] = "honge"; Request. redirect ("Default2.aspx");} receive. aspx: string username = Session ["username"]; To obtain the parameter value.

Method 4:

Use Application

Send. aspx: protected void button#click (object sender, EventArgs e) {Application ["username"] = "honge"; Request. redirect ("Default2.aspx");} receive. aspx: string username = Application ["username"]; To obtain the parameter value.

Method 5:

Use Server. Transfer

Send. aspx: public string Name {get {return "honge" ;}} protected void button#click (object sender, EventArgs e) {Server. transfer ("Default2.aspx");} receive. aspx: send d = Context. handler as send; if (d! = Null) {Response. Write (d. Name); to obtain the parameter value. }

If you can use this method in asp.net 2.0: PreviousPage

PreviousPage d = Context. Handler as PreviousPage;
If (d! = Null)
{
Response. Write (d. Name); to obtain the parameter value.
}

It can also be used as follows:

Send. aspx: receive. aspx: string name = PreviousPage. Name; in this way, the parameter value is obtained.

If MasterPage is used in your page, Server. the PreviousPage passed by Transfer is invalid. I don't know why. so if MasterPage is used, it is best to use Session or Context. items ["username.

  • 2 pages in total:
  • Previous Page
  • 1
  • 2
  • Next Page

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.