简体   繁体   中英

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.

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). 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. I tried returning true in case there was an output expected, but nada. When I commend out the content of processing(){ // stuff } then it works fine, so something in there seems to be killing me.

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. How to stop multiple clicks by user

I had the same type of problem this may or may not help.

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