WEB programming (4 ).... Parameter transfer between pages

Source: Internet
Author: User

I. used:

(1) pass through the URL link address (add ?.. When multiple parameters are added, & para2 = value cannot contain spaces such as href = "receive. aspx? Username = honge & Pwd = 123 ")

Send. aspx:
// Or the page <a href = "receive. aspx? Username = honge "> </a>
Protected void button#click (Object sender, eventargs E)
{Request. Redirect ("receive. aspx? Username = honge ");}
Receive. aspx:
String username = request. querystring ["username"]; To obtain the parameter value.
PS1: The passed parameters are of the string type by default, so no quotation marks or type conversion are required before transmission. The receiver is of the string type. <excluding Chinese characters>

PS2: when multiple parameters are passed, separate them with &. Note that no space is allowed.

PS3: When passing Chinese characters, type conversion is often performed first. system. Web. httputility. urlencode ("Hello! ");

(2) Pass the 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.

(3) using Cook:

Send:
Request. Cookies. Add (New httpcookie ("cookie_stop2_class", "education "));
Receive:
Httpcookie mycook = request. Cookies ["cookie_stop2_class"];
If (mycook! = NULL ){
String STR = mycook. value; // STR = education;

}

 

(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.

(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 );}

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.