ASP. NET cross-page value transfer

Source: Internet
Author: User
Cross-page value transfer definition: refers to the transfer of values between web pages, including simple page form values and pages Program In. Variable transfer value: it can be divided into simple variables such as int A and string B. It also includes transmitting complex objects. Take Asp.net as an example ASP. net cross-page value transfer skills Summary 1. querystring is a simple value transfer method. It displays the transmitted value in the address bar of the browser. This method can be used if one or more security requirements are not high or the structure is simple. However, this method cannot be used to transmit arrays or objects. The following is an example: C # Of A. aspx # Code Private void button#click (Object sender, system. eventargs e) {string s_url; s_url = "B. aspx? Name = "+ label1.text; response. redirect (s_url);} B. in aspx, C # code private void page_load (Object sender, eventargs e) {label2.text = request. querystring ["name"];} 2. the scope of the Application object variable is global, that is, it is valid for all users. The commonly used methods are lock and unlock. A. aspx C # code private void button#click (Object sender, system. eventargs e) {application ["name"] = label1.text; server. transfer ("B. aspx ");} B. in aspx, C # code private void page_load (Object sender, eventargs e) {string name; application. lock (); name = application ["name"]. tostring (); application. unlock ();} 3. the session variable must be the most common usage. Its operation is similar to that of the application and applies to individual users. Therefore, excessive storage will exhaust server memory resources. A. aspx C # code private void button#click (Object sender, system. eventargs e) {session ["name"] = label. text;} B. in aspx, C # code private void page_load (Object sender, eventargs e) {string name; name = session ["name"]. tostring ();} 4. using cookie object variables is also a common method. Like session, Cookie objects are stored on the client, sessions are stored on the server. The cookie must be used in combination with the ASP. NET built-in Object Request. A. aspx C # code private void button#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. in aspx, C # code private void page_load (Object sender, eventargs e) {string name; name = request. cookie ["name"]. value. tostring ();} 5. use server. the transfer method can be said to be the method used by the face object development. It uses Serv The ER. 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 like an object and is simple and effective. A. aspx C # code public string name {get {return label1.text;} private void button#click (Object sender, system. eventargs e) {server. transfer ("B. aspx ");} B. in aspx, C # code private void page_load (Object sender, eventargs e) {A newweb; // instance a form 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.