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 );