views:

50

answers:

2

Can someone point me to a javascript to enable/disable few buttons on an ASP.NET page on the client side. I didnt want to do postbacks for responsiveness

A: 

If you disable buttons using client side javascript, the client can re-enable them. This approach is a 'non-solution' to your problem. It's better to disable them when you are rendering.

If you want fields to only be visible if certain conditions are met in the process of filling out a form, then an AJAX solution (something that uses both client and server side) would fit your needs.

George Stocker
A: 

Here is the code to disable a button:

function disableButton(buttonID)
{
  document.getElementById(buttonID).disabled = true;
}

to call it you'll need to do:

disableButton('<%=button.ClientID%>');

George is right, someone can still monkey with the page to re-enable them, so it depends on what you are trying to stop. We disable buttons so that most people don't double click and submit information twice etc. If someone really wanted to they could re-enable etc., but this solves about 99% of our headaches where we use it.

Kevin
I changed the OnClick like belowonclientclick="disableButton('<%=ClearButton.ClientID%>');"but I get an MS JScript runtime error: document.getElementById(...) is null or not an object..
Nevin Mathai