views:

242

answers:

3

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:

RadioButton
RadioButtonList
CheckBox
CheckBoxList
TextBox
DropDownList
Button
etc...

I need a Simple and short method to disabled all the Controls when i call this jQuery method on some condition. Any Help?

Thanks in Advance...

A: 

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.

ArsenMkrt
A: 
$('input,select').attr('readonly', 'readonly');
Darin Dimitrov
There are Asp controls as well...
Sanju
What do you mean *Asp controls*? jQuery knows nothing about Asp, it only sees your HTML structure.
Darin Dimitrov
A: 

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.

Guffa