0

Without using jQuery (can't get into why NOT right now) how do I disable an ASP.NET button from being "clickable" if a certain client-side condition is not met?

1
  • why aren't you able to remove the button from asp.net ? Javascript can be disabled and any advanced user will be able to click on the button if they want to... Commented Jun 7, 2011 at 19:51

4 Answers 4

2

You can do something like this with pure javascript.

if(someCondition)
    document.getElementById("buttonClientID").disable = true;
else
    document.getElementById("buttonClientID").disable = false;
Sign up to request clarification or add additional context in comments.

Comments

2

The button will be rendered as an <input> tag on the client side. Find the input using the standard JavaScript document.getElementById and set its disabled property to true.

Comments

2

OnClientClick="return false;" will prevent the post back, without disabling the button. And you can add an alert('button disabled') if wanted.

Comments

1

Use javascript:

document.form1.button.disabled=true;

or try

document.getElementByID('myButton').disabled=true;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.