简体   繁体   English

执行javascript函数和代码函数的顺序?

[英]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服务器按钮,我有onClick代码执行代码和onClientClick执行javascript函数。

<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? 我无法确定是先生成onClick事件还是先执行onClientClick,还是先并行执行? I want onClick event to be generated first and then onClientClick because the latter needs value retrieved from the former. 我想首先生成onClick事件然后onClientClick,因为后者需要从前者检索的值。

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? 如果你想控制执行的顺序,你可以只创建一个javascript函数,以所需的顺序调用你的另外两个函数,并将一个函数挂钩到onclick而不是将任何东西留给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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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