Monday, 13 August 2018

How to disable all controls on page in asp.net

We have several ways to do this:

Jquery
     a) Specific control type
        $('input[type=submit], select, input[type=text], input[type=button], input[type=checkbox], input[type=radio], textarea, a').not('#ContentPlaceHolderMiddle_btnTEsting').removeAttr('onclick').removeAttr('href').attr({ 'disabled': 'disabled' });
       
     b) All Controls
        $("*").not('#ContentPlaceHolderMiddle_btnTEsting').removeAttr('onclick').removeAttr("href").attr({ "disabled": "disabled" });

Javascript

       var vControl = document.forms[0].elements;
       var vControlAnchor = document.forms[0].getElementsByTagName('a');
     
       for (j = 0; j < vControlAnchor.length; j++) {
         vControlAnchor[j].removeAttribute('href');
         //document.forms[0].getElementsByTagName('a')[0].removeAttribute('href');
       }
       for(i = 0; i< vControl.length; i++)
       {
         vControl[i].disabled = true;
       }

No comments:

Post a Comment