Matt
Matt

Reputation: 5660

Javascript to Prevent ASP.NET button click

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?

Upvotes: 0

Views: 398

Answers (4)

noinstance
noinstance

Reputation: 761

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

Upvotes: 2

JonH
JonH

Reputation: 33143

Use javascript:

document.form1.button.disabled=true;

or try

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

Upvotes: 1

Bala R
Bala R

Reputation: 108937

You can do something like this with pure javascript.

if(someCondition)
    document.getElementById("buttonClientID").disable = true;
else
    document.getElementById("buttonClientID").disable = false;

Upvotes: 2

FishBasketGordo
FishBasketGordo

Reputation: 23132

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.

Upvotes: 2

Related Questions