Asp. NET page jump and the way to pass value

Source: Internet
Author: User

Asp. NET page Jump related knowledge

First, <a> label1. <a href= "test.aspx" ></a>2. This is the most common method of steering;
Second, Hyperlink control1. ASP. NET Server-side control properties NavigateUrl specifies the URL address to jump to2. NavigateUrl is a code modification that can be used on the server side, which differs from <a>3. Because the hyperlink itself has no events, set the NavigateUrl in the other events on the server side4. code example:<asp:hyperlink id= "HyperLink" runat= "Server" navigatoeurl= "test.aspx" >ok</Asp:HyperLink>Third,Response.Redirect () method 1. Process: Send an HTTP response to the client, notify the client to jump to a new page, and then send the client a jump request to the server side. 2. After the page jumps, all the information saved by the internal control is lost, and when a jumps to the B,b page, it will not be able to access the data submitted by page A. 3. Use this method to use this method to jump after the browser address bar URL information changes4. You can use the session Cookies application and other objects for data transfer between pages5. The redirect operation occurs on the client side and involves two communications with the Web server in total: One request for the original page, and another one to redirect the new pageFourServer.Transfer () method1. Implement page jumps while handing over control of the page2. The information stored in the request session is unchanged during the page jump, and the data submitted by the previous page can be used after the jump.3. The URL of the browser address bar does not change after the jump4. The redirect request for this method is performed on the server side, and the browser does not know that the page has occurred a jump
V.Server.Execute () method 1. This method allows the current page to execute another page on the same Web server2. Once the page has finished executing, return to the original page where Server.Execute () was issued. 3. This method is similar to a function call for a page The requested page can use the original page's form data and query string collection4. Set the enableViewStateMac property of the page directive of the invoked pages to FalseJavaScriptstring str = "<script language=javascript>history.go ( -2);</script>"; Response.Write (str); PS:1. It is best to use the Response.Redirect method in order to ensure the legitimacy of the Html output, because the Server.Execute or Server.Transfer method returns to the client page that contains multiple <Html>< Body> tags, not legitimate HTML pages, may cause errors in non-IE browsers. 2. Because Server.Transfer performs redirection on the server side, unnecessary network traffic is avoided, resulting in better performance and browsing results.

Using querystring to pass values

Response.Redirect("b.aspx?username=" + TextBox1.Text.Trim () + "&&pwd=" + TextBox2.Text.Trim ());

Use Session to pass value

session["username"] = TextBox1.Text.Trim ();

session["pwd"] = TextBox2.Text.Trim ();

Response.Redirect("b.aspx");

Using application to pass values

application["username"] = TextBox1.Text.Trim ();

application["pwd"] = TextBox2.Text.Trim ();

Response.Redirect("b.aspx");

Using cookies to pass values

HttpCookie HC = new HttpCookie ("username", TextBox1.Text.Trim ());

HttpCookie HC2 = new HttpCookie ("pwd", TextBox2.Text.Trim ());

Response.appendcookie (hc);//Add the created cookie to the internal cookie collection

Response.appendcookie (HC2);

Server.Transfer("b.aspx"); Cookies need to use Server.Transfer to jump

Using Server.Transfer to pass values

The Server.Transfer method directs the process from the current page to another page, and the new page uses the reply stream of the previous page, so this method is a fully-faceted object.

Server.Transfer("b.aspx");

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.