简体   繁体   English

JavaScript有时会阻止服务器事件使用asp.net触发

[英]JavaScript sometimes prevents server event from firing with asp.net

I have what I thought was a pretty straightforward javascript issue, but I'm starting to go nuts trying to figure out my problem. 我有一个我认为非常简单的javascript问题,但是我开始发疯试图找出问题所在。

I have a slow page, and it was possible for users to click submit, then click another button while waiting on the page to load, it was creating issues. 我的页面运行缓慢,有可能用户单击“提交”,然后在等待页面加载时单击另一个按钮,这正在创建问题。 I thought I could display a please wait message and disable the submit button on click. 我以为我可以显示请稍候消息,并在单击时禁用“提交”按钮。 Below is the function, I am using asp.net 3.5 so there's a name mangling issue, because of this I was using a getElemenetsByName and scanning for the right items (not awesome but it seems to work). 下面是该函数,我正在使用asp.net 3.5,因此存在名称更改问题,因此,我正在使用getElemenetsByName并扫描正确的项(虽然很棒,但似乎可行)。 When I run this, the button becomes disabled, but then the page just sits there, the server never gets called. 当我运行此命令时,该按钮将被禁用,但随后该页面仅位于该位置,服务器将永远不会被调用。 I tried in firefox and I didn't see any errors in firebug, but when I set a breakpointon the server, the server def does not get called. 我在firefox中尝试过,但在firebug中没有看到任何错误,但是当我在服务器上设置断点时,不会调用服务器def。 I tried returning true in case there was an output expected, but nada. 我尝试返回true以防万一有预期的输出,但是nada。 When I commend out the content of processing(){ // stuff } then it works fine, so something in there seems to be killing me. 当我推荐processing(){ // stuff }的内容时,它可以正常工作,因此其中的某些内容似乎正在杀死我。

function processing() {
    var pleaseWaitID = "lblPleaseWait";
    var submitBtnName = "btnSubmit";
    var submitControl = document.getElementsByTagName('input');

    var pleaseWaitlbls = document.getElementsByName(pleaseWaitID);

    for (pleaseWait in pleaseWaitlbls) {
       if (pleaseWaitlbls[pleaseWait].style != null) {
            pleaseWaitlbls[pleaseWait].style.visibility="visible";
       }
    }

    for (submitButton in submitControl) {
       if (submitControl[submitButton].name != null) {
           if (submitControl[submitButton].name.search(submitBtnName) != -1) {
               submitControl[submitButton].disabled = "disabled";
           }
       }
    }

    return true;
}

..... .....

 asp:Button ID="btnSubmit" name="btnSubmit" SkinID="MainAction" runat="server" Text="Submit" OnClientClick = "javascript:processing();"
 OnClick="btnSubmit_Click" meta:resourcekey="btnSubmitResource1"

Any ideas on what I've screwed up here? 关于我在这里搞砸了的任何想法吗?

Thanks you for your time. 谢谢您的宝贵时间。

Asp.net Custom user control button. Asp.net自定义用户控制按钮。 How to stop multiple clicks by user 如何停止用户的多次点击

I had the same type of problem this may or may not help. 我遇到过相同类型的问题,这可能会或可能不会有所帮助。

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

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