Several ways to transfer values between. NET pages

Source: Internet
Author: User

1. QueryString

This is the simplest way to pass a value, but the disadvantage is that the value of the pass is displayed in the browser's address bar and cannot be passed on to the object, only for simple delivery and low security requirements.

Delivery: location.href= "webform2.aspx?name=" + yourname&&name2= "+ yourName2;

Receive: String name = request.querystring["Name"];

2. Form

Delivery: Based on the name and value of the control in the form, such as:

<form id= "Form1" method= "POST" >

<input type= "text" name= "name" value= "xxx"/>

</form>

The form needs to be submitted <input type= "Submit"/> or document.getElementById ("Form1"). Submit ();

Receive: String name = request.form["Name"];

3. Session

It is important to note that storing too much data in the session variable consumes more server resources, and some cleanup actions should be used to remove unwanted sessions when using the session.

Removal: Session.remove ("name");

Delivery: session["name"] = YourName;

Receive: String name=session["name"]. ToString ();

4. Cookies

Delivery: HttpCookie cookie_name = new HttpCookie ("name");

Cookie_name. Value = YourName;

Response.appendcookie (Cookie_name);

Receive: request.cookies["name"]. Value;

5. Application

The Application object is scoped to the whole global, which means it is valid for all users. Its common method is to use lock and unlock.

Pass: application["name"] = name;

Reception: Application.Lock ();

String name = application["Name"]. ToString ();

Application.UnLock ();

Lock is designed to prevent multi-threaded tampering, ensuring that the moment

6. Server.Transfer

Passed:

WebForm1 write the attributes that need to be passed to the value such as:

public string Name {get{return txtname.text;}}

Execution Server.Transfer ("webform2.aspx");

Receive:

Receive parameters in WebForm2:

WebForm1 wf1= (WebForm1) Context.Handler;

Response.Write (WF1. Name);

Several ways to transfer values between. NET pages

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.