we can make asp.net Linkbutton Enable\Disable in Javascript. normally disabled='disabled' attribute works only in internet explorer not in Mozilla. to resolve this problem we can develope a javascript function Which perform this.
(1) Suppose we have a LinkButton
<asp:LinkButton ID="lnkTest" runat="server" CommandArgument="1" CommandName="1x"
OnClick="lnkTest_Click">Test</asp:LinkButton>
(2)Style for enabling and Disabling is
<style>
.LnkEnabled
{
cursor: pointer;
}
.LnkDisabled
{
cursor: default;
color: Gray;
}
</style>
(3) and javascript fiuction is
<script language="javascript">
function EnableLinkButton(ID,flag)
{
document.getElementById(ID).onclick=function(){return flag;};
if(!flag)
{
document.getElementById(ID).setAttribute("disabled","disabled");
document.getElementById(ID).className="LnkDisabled";
}
else
{
document.getElementById(ID).setAttribute("disabled","");
document.getElementById(ID).className="LnkEnabled";
}
}
EnableLinkButton('<%= lnkTest.ClientID %>',false);
</script>
Calling above javascript function we can Enable or disable LinkButton from Javascript.
Thanks.
A blog where you can find tutorials on ASP.Net, Ajax Control Toolkit, SQL Server 2008/2005, WCF, Silverlight, Azure and other Microsoft Technologies
Monday 25 May 2009
2 comments:
Comments posted on ASP.Net Ajax Tutorials Blog are moderated and will be approved only if they are on-topic and not abusive. Please email me or my team for tech-support or blogging related questions. Avoid including website URLs in your comments - Thanks Author
Subscribe to:
Post Comments (Atom)
Hi its very useful.
ReplyDeleteHi..Thanks a lot for this information. But its not working in Mozilla Firefox. I mean, Linkbutton color is not changing to Gray color. Can you please help me to disable a linkbutton in Firefox?..
ReplyDeleteThanks in advance for your help.