Jump issue between pages

In Web applications, many times we need to jump to another page, the page can be turned to this application, the application may be outside of this system. To this end, we either jump directly, or submitted to the server after the jump, in order to achieve this functionality in .Net total of four different methods: hyperlink, server transfer, and cross-browser redirect page transmission. Here we have to introduce the four methods are:

One, hyperlink

    Surely we have used HyperLink control it, after we set it NavigateUrl Properties, click on it to jump back to the page referred to, without the need for server returns.

Second, the server transmission

    It refers to the Server.Transfer method.

    Transfer method HttpServerUtility class will .htm or .aspx page (Note: You can not be .asp pages) of the URL as a string parameter, back to the server, and then to terminate the operation of the current page to the start page of our requests aim to be accessed.

    It is worth noting that when using Server.Transfer method is called when HttpResponse.End because the method of the current page will always lead to ThreadAbortException this exception. This exception is usually not a problem, but in times of () statement in the block Try ... .Catch based database transaction operations, will cause the transaction can not be committed. Unless explicitly caught ThreadAbortException this exception, we look at the following example:  

 

    The try
    {
       Transaction.commit ();    
// perform transaction        the Server.Transfer ( "Test.aspx ? ID = +  ID);  // If successful, then go to the appropriate page Line Transaction     }     the Catch (the ThreadAbortException EX)     { // capture the abnormal     }     the Catch (exception EX)     {        Transaction.rollback ();                 // rollback transaction     }     the Finally     {        Connection.Close ();               // close the connection     }




       









 

    In addition, the source page using Server.Transfer method and the target page must be in the same application. And the method does not use the time to verify that the current user has permission to view the target page. If this point is very important for your application is the case (such as rights management involved in the system, then), do not use this method.

    When redirected to a new page, you will notice that the words carefully URL in the browser address bar or the original page address instead of the current page. Browser history will not show the jump, so click your browser's "back" button generally will not fall back to the original page.

    In the overloaded Server.Transfer method is provided of a Boolean parameter, if the parameter is set to true, then it will retain the original page QueryString and Form collections, which for the time necessary to complete the transfer of control to another page, this overloaded method will be very useful. The default is false.

    Remember: one page to another page of the course (even if stored in a hidden view state form field, the data will not be saved). This is because when the view state of the page level, so jump to another page with Server.Transfer method, view state will fail.


Third, the browser redirects

    It refers to the Response.Redirect method

    Redirect method HttpResponse class corresponds to a programmable HyperLink. This method .htm or .aspx page (Note: You can not be .asp page) URL address as a string parameter, without going through the server's return, the client directly perform a redirect. Thus faster than the corresponding speed in contrast Server.Transfer method. Because it is a completely new server requests, so it is forced to complete authentication and authorization.

    Unless with one application, or it can not be transferred from the source page to the target page of data. In this case, the data transfer may be implemented using a session state or application state.

    And Server.Transfer method as in Response.Redirect overloaded methods have a Boolean parameter, the parameter is true if said executed this page should be terminated.

Fourth, cross-page transmission

    Pages can be submitted to the server, and then send it directly to another page. We can achieve this functionality by PostBackUrl property specific control. When this method can only be sent to another .aspx page instead of .htm or .asp pages, current page controls access can be achieved by Page.PreviousPage property.

    If the source page and a target page in the same application, you can share session state and application state, as well as public members of the source page. Page can be sent to another page spread outside the application, but the target page data source page can not be used.

    If you can access the PreviousPage property in the target, the source page will be instantiated again, but also to restore the view state from the source page. Thus, using the PreviousPage property execution performance are directly affected by the view state of the source page is stored data size.

    There is nothing wrong in the essay place please a lot of criticism, more exchanges!

    I made a Demo, the latter three methods to achieve the next, we can see the effect (click to download )

Reproduced in: https: //www.cnblogs.com/shimeng3344518/archive/2007/04/18/718551.html

Guess you like

Origin blog.csdn.net/weixin_33896069/article/details/94682761