简体   繁体   中英

Order of execution of javascript function and code behind function?

I have a asp server button for which I have onClick for code behind code execution and onClientClick to execute javascript function.

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
        style="z-index: 1; left: 648px; top: 202px; position: absolute" 
        Text="Show route" OnClientClick="droute(); return false" />

I am unable to determine whether onClick event is generated first or onClientClick is executed first or do they run parallel? I want onClick event to be generated first and then onClientClick because the latter needs value retrieved from the former.

If you want to control the order of execution, you can just make one javascript function that calls your two other functions in the desired order and hook that one function up to onclick and not leave anything up to ASP.NET?

<asp:Button ID="Button1" runat="server" onclick="thisClick()" 
    style="z-index: 1; left: 648px; top: 202px; position: absolute" 
    Text="Show route"/>

function thisClick() {
    Button1_Click.apply(this, arguments);
    droute.apply(this, arguments);
    return false;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM