C # Six Methods for passing parameter values between pages

Source: Internet
Author: User

QueryString is a simple method for transferring values. It can display the transmitted values in the address bar of the browser. when one or more values with low security or simple data are passed, an array or object can be used.

Private void button#click (object sender, System. EventArgs e) {string url; url = "B. aspx? Name = "+ Lable1.Text;} c # code private void Page_Load (object sender, EventArgs e) in B. aspx {Lable2.Text = Request. QueryString [" name "];}

Query values are classified into post and get formats.

// Post request

String name = Request ["name"]. toString ();

String name = Request. Form. Get ("name"). toString ();

// Get request
String name = Request. QueryString ["name"]. toString ();
However, I found that both post and get values are available.
String name = Request ["name"]. toString ();

Application object Value passing

A. aspx c # code

private void Button1_Click(object sender, System.EventArgs e){    Application["name"]=Label.Text;    Server.Transfer("b.aspx");}

B. aspx c # code

private void Page_Load(object sender, EventArgs e){    string name;    Application.Lock();    name=Application["name"].ToString();    Application.UnLock();}

Use Session Variables

A. aspx c # code

private void Button1_Click(object sender, System.EventArgs e){    Session["name"]=Lable.Text;    }

B. c # code in aspx

private void Page_Load(object sender, EventArgs e){    string name=Session["name"].ToString();}

Use Cookie object variables

A. C # code in aspx

private void Button1_Click(object sender, System.EventArgs e){    HttpCookie cn=new HttpCookie("name");    cn.Value=Lable.Text;    Reponse.AppendCookie(cn);    Server.Transfer("b.aspx");}

B. c # code in aspx

private void Page_Load(object sender, EventArgs e){    string name=Request.Cookie["name"].Value.ToString();}

Use the Server. Transfer () method

A. aspx c # code

public string Name{    get{return Lable1.Text;}}private void Button1_Click(object sender, System.EventArgs e){    Server.Transfer("b.aspx");}

B. aspx c # code

private void Page_Load(object sender, EventArgs e){    a newWeb;    newWeb=(source)Context.Handler;    string name;    name=newWeb.Name;}

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.