开发者

Javascript to Prevent ASP.NET button click

Without using jQuery (can't get into why N开发者_如何学编程OT right now) how do I disable an ASP.NET button from being "clickable" if a certain client-side condition is not met?


You can do something like this with pure javascript.

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


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.


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


Use javascript:

document.form1.button.disabled=true;

or try

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜