An interesting client registration event

        When writing code for a very ordinary, suddenly I found a very interesting question, window.location.href client can not perform?
        The code is simple. We place a BUTTON control in the page, then add the client registration code in the Page_Load event on the server side:

None.gif if  ( ! Page.IsPostBack)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
this.Button1.Attributes["onclick"= "javascript:return ConfirmSelect();";
ExpandedBlockEnd.gif}
In the client's javascirpt in:
None.gif function ComfirmSelect()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    window.location.href 
= "abc.aspx";
InBlock.gif    
//return false;
ExpandedBlockEnd.gif
}

    According assumed logic should perform the window.location directly from the client, without the need to return to the server. In fact it? This event is not executed at the client, server-side Button1_Click event is still to be executed.
    We then client-side Javascript rewrite it, and see what happens:
None.gif function  ComfirmSelect ()
ExpandedBlockStart.gifContractedBlock.gif
{     Alert ( " first run! " );     window.location.href = " abc.aspx " ;     Alert ( " performing a second! " ); // return to false; } dot.gif
InBlock.gif

InBlock.gif

InBlock.gif

InBlock.gif    

ExpandedBlockEnd.gif
    We will note that in the implementation of the first alert (), the progress bar in the status bar is not loaded, followed, a second alert will be displayed in the progress bar loaded state (). Then we can notice, window.location service side of the event has been covered. That is registered in the server client events for window.location is invalid.
    Now we return false comments to remove this line, and see approach. In this case, only the first alert is logical to deal with, and then the page is passed to the server once again perform a second alert (), and finally go to the page I want. (Sequence backwards?)

       Is unclear why this is so, hoping to get answers.

Reproduced in: https: //www.cnblogs.com/badwood/archive/2006/11/19/564966.html

Guess you like

Origin blog.csdn.net/weixin_33873846/article/details/92853003