Disabling all the Page Control through jQuery

后端 未结 4 787
有刺的猬
有刺的猬 2021-01-26 16:29

I am working on asp.net and c#.

I am using lots of ASP and HTML controls on the page and in some cases all the controls gets disabled. Some of the used Controls are:

相关标签:
4条回答
  • 2021-01-26 16:51

    Strictly speaking you can't disable any server controls at all using jQuery, the server controls only exist while the page is rendered on the server, when the page arrives in the browser only the rendered code is left of the controls.

    You have to find out what html elements are rendered from the controls and disable those elements. For example:

    $('input[type=submit], input[type=checkbox], select, input[type=text], textarea').attr('disabled','disabled');
    

    Note that a control can be rendered as different html elements depending on it's attributes. A TextBox with TextMode=SingleLine is rendered as an input type="text", while a TextBox with TextMode=MultiLine is rendered as a textarea.

    0 讨论(0)
  • 2021-01-26 16:57
    $('input,select').attr('readonly', 'readonly');
    
    0 讨论(0)
  • 2021-01-26 16:58

    Can you put all that controls in the Panel? you can disable panel, and all controls in it will be disabled, in JS it's as easy as disabling div tag, in BE it's easier.

    0 讨论(0)
  • 2021-01-26 17:12

    You can use a below code for this purpose:

    js on click:

    $('body').append('<div class="noclick" />');
    

    once done:

    $(".noclick").remove();
    

    css:

    .noclick {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 9999; /* or maybe higher */
        background-color: transparent;
    }
    
    0 讨论(0)
提交回复
热议问题