I want to comment on the De thief blog garden stolen at on February 24, (1) font size: T | the method for transferring page values has aroused a lot of discussion. This article summarizes Asp.net's cross-page value passing skills.
AD:
ASP. NET cross-page value transfer: Use the querystring variable
Querystring is a simple method for transferring values. It can display the transmitted values in the address bar of a browser. This method can be used to transmit one or more numeric values with low security requirements or simple structure. However, this method cannot be used to pass arrays or objects. The following is an example:
A. aspx C # code
- private void Button1_Click(object sender, System.EventArgs e)
- {
- string s_url;
- s_url = "b.aspx?name=" + Label1.Text;
- Response.Redirect(s_url);
- }
-
B. C # code in aspx
- private void Page_Load(object sender, EventArgs e)
- {
- Label2.Text = Request.QueryString["name"];
- }
ASP. NET cross-page value transfer: Use the application object variable
The scope of the Application object is global, that is, it is valid for all users. The common methods are lock and unlock.
A. aspx C # code
- private void Button1_Click(object sender, System.EventArgs e)
- {
- Application["name"] = Label1.Text;
- Server.Transfer("b.aspx");
- }
-
B. C # code in aspx
- private void Page_Load(object sender, EventArgs e)
- {
- string name;
- Application.Lock();
- name = Application["name"].ToString();
- Application.UnLock();
- }
-
ASP. NET cross-page value transfer: Use session Variables
Presumably, this is definitely the most common usage. Its operations are similar to those of the application, which act on individual users. Therefore, excessive storage will result in the depletion of server memory resources.
A. aspx C # code
- private void Button1_Click(object sender, System.EventArgs e)
- {
- Session["name"] = Label.Text;
- }
-
B. C # code in aspx
- private void Page_Load(object sender, EventArgs e)
- {
- string name;
- name = Session["name"].ToString();
- }
-
ASP. NET cross-page pass value: use cookie object variable
This is also a common method. Like session, it is for every user, but there is a fundamental difference, that is, cookies are stored on the client, session is stored on the server. In addition, the use of cookies should be used with the Asp.net built-in Object Request.
A. aspx C # code
- private void Button1_Click(object sender, System.EventArgs e)
- {
- HttpCookie cookie_name = new HttpCookie("name");
- cookie_name.Value = Label1.Text;
- Reponse.AppendCookie(cookie_name);
- Server.Transfer("b.aspx");
- }
-
B. C # code in aspx
- private void Page_Load(object sender, EventArgs e)
- {
- string name;
- name = Request.Cookie["name"].Value.ToString();
- }
-
ASP. NET cross-page value transfer: Use the server. Transfer Method
This can be said to be the method used for face object development. It uses server. the transfer method directs the process from the current page to another page. The new page uses the response stream of the previous page. Therefore, this method is completely object-like and concise and effective.
A. aspx C # code
- public string Name
- {
- get{ return Label1.Text;}
- }
- private void Button1_Click(object sender, System.EventArgs e)
- {
- Server.Transfer("b.aspx");
- }
B. C # code in aspx
- Private void page_load (Object sender, eventargs E)
- {
- A newweb; // instance a form
- Newweb = (source) Context. Handler;
- String name;
- Name = newweb. Name;
- }
The above is the Asp.net cross-page value transfer technique summarized in my practice.