Thursday, October 01, 2009

Disabling an ASP.NET Button when Clicked

Disabling an ASP.NET Button when Clicked or On Mouse click
tried this...
<asp:Button runat="server" Text="My Button" OnClientClick="this.disabled=true;" />

it failed but. Why? because if you disable a button in the onclick it doesn't post back. the button gets disabled before the form posts back.

Instead of disabling the button when you click it, set the onclick event to fire a function that returns false. So it looks something like this:

<asp:Button runat="server" Text="My Button" OnClientClick="this.onclick=new Function('return false;');" />

or you can disable an ASP.NET Button, in the following way

<a href="#">
<img id="btnSubmit" height="39" alt="Next Page" src="Media/Global/nextpage-off.GIF"
width="132" border="0" name="btnSubmit" onclick="ConfirmVisittype();new Function('return false;');"></a>

or you can disable an ASP.NET Button, in the following way

<a href="#">
<img id="btnSubmit" height="39" alt="Next Page" src="Media/Global/nextpage-off.GIF"
width="132" border="0" name="btnSubmit" onclick="ConfirmVisittype();" onmousedown=fndis();></a>

function fndis()
{
document.getElementById('btnSubmit').onmousedown=function(){};
}


or

function beginRequest(sender, eventArgs)
{
// Get the button
var Button1 = $get('<%=Button1.ClientID %>')
// Set its text to Loading
Button1.value = 'Loading';
// Disable the Button
Button1.disabled = true
}

or



Hope it helps...

No comments: