开发者

JavaScript sometimes prevents server event from firing with asp.net

开发者 https://www.devze.com 2023-03-02 22:06 出处:网络
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 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 serv开发者_如何学Cer, 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号