Disabling LinkButton doesn't disable the click event in javascript

后端 未结 7 1618
悲哀的现实
悲哀的现实 2020-12-10 09:08

I want to disable a LinkButton clink on the client site.

objLinkButton.disabled = true;
// or 
objLinkButton.disabled = -1;

Th

7条回答
  •  误落风尘
    2020-12-10 09:43

    I am building on tvanfosson 's answer. His answer using jQuery works well, but if you have validators it messes things up. Here goes:

    var code = null;
    $(document).ready(function () {
        var button = $('#SubmitPaymentLnkBtn');
        code = button.attr('href').replace(/javascript:/, ''); 
        button.attr('href', '#'); // replace postback function
        button.click(function () {
            if (Page_ClientValidate('PaymentInfo')) {
                               // now only runs if above validationGroup is valid
                $(this).unbind('click'); 
                if (code) {
                    $(this).addClass('disabled-btn');
                    eval(code);  // do post back
                } 
            }
        });
    });
    

    Then in your markup, be sure to set ClientIDMode to Static.

    
    

提交回复
热议问题