Use session to record the page address and implement the page return Function

Source: Internet
Author: User

In the development process, to meet the customer's requirements, we need to implement this function: click a text connection in page a to enter Page C. After clicking the return button, we can return to page, this text link is also available on page B. After you click it, the C page is displayed. When you return the result, the B page is returned (only one return button is available on Page C ). the session function is used to record the page from which the session jumps when you jump to the C page, and then click the return button to determine the session content, this determines whether to return page a or page B.

First, add the code to get the page path on the pages a and B.

String url = request. currentexecutionfilepath. tostring ();

// Obtain the virtual path of the current page

Session ["url"] = URL;

Response. Redirect ("C. aspx", true );

On page C, first obtain the virtual path of the previous page through session.

String url = session ["url"]. tostring ();

Because. the first half of the virtual path on the two pages of B is the same. In fact, we only need to determine that it is ". aspx "or" B. aspx. therefore, we need to use the split method to obtain the desired page name, and then assign the name to a label, hide the label in the page (whether to use lable to save the Page name depends on the situation ).

String [] split = URL. Split (New char [] {'/'});

Int n = split. length;

String pathname = splits [n-1];

Label1.text = pathname;

Finally, in the response event of the return button, determine the page to return:

If (label1.text = "A. aspx ")

Response. Redirect ("A. aspx", true );

Else

Response. Redirect ("B. aspx", true );

 

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.