Solution:
Program Introduction
Main Interface: List of undelivered orders (http: // localhost: 18888/Order/UnfilledOrdersList. aspx)
Subinterface: Order details (http: // localhost: 18888/Order/ViewOrderDetail. aspx? OrderId = id, where the value of id is the id of the order information selected on the main interface)
The home page is the main information of an order. The GridView has a HyperLink control that redirects to the "Order details" page to view the Order details.
The subinterface has a "return" Button, which redirects back to the main interface.
The program initially in the return button is:Copy codeThe Code is as follows: # region return button
Protected void btnReturn_Click (object sender, EventArgs e)
{
String url = Request. QueryString ["Url"] = null? "": Request. QueryString ["Url"]. ToString ();
Response. Redirect (url );
}
# Endregion
After debugging, the value obtained by the url is always a Null String, that is, the url is always "", so the main interface is always not returned.
After checking the information, I changed the program:
Copy codeThe Code is as follows: // The code added in the page loading event
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
/****** The following code must be included in the determination of whether it is a sending back event, otherwise it will not be effective ******/
If (Request. UrlReferrer! = Null)
{
ViewState ["retu"] = Request. UrlReferrer. ToString ();
}
}
}
# Region return button
Protected void btnReturn_Click (object sender, EventArgs e)
{
String url = ViewState ["retu"]. ToString () = null? "": ViewState ["retu"]. ToString ();
Response. Redirect (url );
}
The modified code, after debugging, url = http: // localhost: 18888/Order/UnfilledOrdersList. aspx, that is, the address of the main interface, can be returned to the main interface correctly.
Program Description: when a user requests a page through a client browser, the page runs for the first time. The statement "ViewState [" retu "] = Request. urlReferrer. toString (); "gets the URL of the previous page of the request. Put this statement in "if (! IsPostBack) {} "the statement is fast, because when the user inputs information, selects from the options, or clicks the button, the page may be sent to the Web server again, in ASP. NET is called "sending back ". More accurately, the page will be sent by itself. Therefore, the statement "ViewState [" retu "] = Request. urlReferrer. toString (); "only needs to be executed on the Page of the first request, instead of at each sending back. In this case, the IsPostBack attribute of the Page object is used to avoid unnecessary processing of the round-trip.
In "if (! IsPostBack) {} "under the breakpoint debugging, you can clearly see this process.
Episode: differences between LinkButton and HyperLink in ASP. NET
Because of the problem that the main interface jumps to the sub-interface, you need to link the link. Both LinkButton and HyperLink can be implemented. After checking some information, I finally chose HyperLink, this is because simple redirection does not require server-side processing. Here we will introduce the differences between LinkButton and HyperLink:
1) LinkButton supports sending back. The server can process page jumps and navigate the user to the target URL. Therefore, you can do some processing before linking to the new page, input the validation, and combine the new URL. HyperLink is not sent back to the server and cannot be processed by the server.
2) The LinkButton control implements page Jump by using methods such as Response. Redirect In the Click event. HyperLink only needs to set NavigateUrl to redirect the page,
The largest usage area is that LinkButton has a Click event, but HyperLink does not.