tags:

views:

101

answers:

3

How to disable the asp.net Link buttons and asp.net radio buttons. I have used

to enable $("#sLbtnFirst").attr("disabled", ""); to disable $("#sLbtnFirst").attr("disabled", "disabled");

but i'm able to click the buttons they are just greying

A: 

In .NET radio buttons, the attribute that specifies whether they're clickable is called "enabled", not "disabled".

But, at client-side they are rendered as html input tags which do contain the attribute "disabled" so to disable them you would want to use:

$("#sRbtnFirst").attr("disabled", "disabled");

To enable:

$("#sRbtnFirst").removeAtrr("disabled");

EDIT: I've tried your jQuery myself in a .NET app and it seems to grey out the radio buttons fine (and prevent clicking). The LinkButton's a different story though.

You'll also need to remove the "href" attribute to prevent it from performing an action on click. So:

$("#sLbtnFirst").attr("disabled", "disabled");
$("#sLbtnFirst").removeAttr("href");

That should disable the LinkButton.

Also, remember that your IDs will change when they are rendered in the form so they won't be what they are when you view your aspx page in Visual Studio. .NET will change them into something like:

#ct100_sLbtnFirst
fat_tony
A: 

Link buttons render as anchor tags (<a href=) and the disabled attribute is not defined for this tag. As far as radio buttons are concerned you could apply the disabled attribute to them, they will grey out and their value won't be sent when you post the form.

Darin Dimitrov
A: 

To enable/disable linkbutton, try this:

//disabling
document.getElementById('sLbtnFirst').onclick = function() {return false;}
//enabling
document.getElementById('sLbtnFirst').onclick = function() {return true;}
Jarek