简体   繁体   English

__doPostBack不会在首次点击时触发

[英]__doPostBack doesn't fire on the first click

Just like the title says. 就像标题说的那样。 I have some javascript on a page that is supposed to fire a __doPostBack call if other variables/conditions on the form are valid. 我在页面上有一些JavaScript,如果表单上的其他变量/条件有效,则应该触发__doPostBack调用。

function DoPostBack() { 
    var valid = true;
    if (SomethingHappens) { 
        valid = false 
    }

    alert("Is_Valid? " + valid) //evaluates to  true
    if (valid) { 
       __doPostBack("btnSubmit",''); //First click here does nothing, despite it being it by code. Works fine the second time. 
    }

And that is hooked up to a button as follows: 并将其连接到按钮,如下所示:

<input ID="btnSubmit" runat="server" onclick="DoPostBack();" type="button" value="Submit"  style="width:80px"/>

What is causing the first click of the submit button to be ignored? 是什么导致忽略提交按钮的第一次单击? I have confirmed that this is the behavior I am seeing by placing a breakpoint in my page_load event. 我通过在page_load事件中放置一个断点来确认这是我所看到的行为。 The first time __doPostBack is called, the breakpoint is not hit, the second time, it is hit. 第一次调用__doPostBack时,未命中断点,第二次调用了断点。

如果您说的是正确的,则应该执行您的函数,因为事实并非如此,那么至少您所说的内容是不正确的。

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

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