Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to completely disable the link button? [duplicate]

Tags:

asp.net

Possible Duplicate:
Disabling LinkButton doesn't disable the click event in javascript

I have a linkbutton in ASP.NET.

I have set its property Enabled = false;

<asp:LinkButton ID="lnkButton" runat="server" 
                Enabled = "false" 
                OnClientClick="return confirm('Are you sure ?')" > Click Me
                        </asp:LinkButton>

Event thought I have set the property Enabled = false the OnClientClick event is still fired.

How can I prevent the OnClientClick event from firing?

like image 855
Rajbir Singh Avatar asked Mar 13 '12 11:03

Rajbir Singh


1 Answers

This is from Disables the link button

/// <summary>
/// Disables the link button.
/// </summary>
/// <param name="linkButton">The LinkButton to be disabled.</param>
public static void DisableLinkButton(LinkButton linkButton)
{
    linkButton.Attributes.Remove("href");
    linkButton.Attributes.CssStyle[HtmlTextWriterStyle.Color] = "gray";
    linkButton.Attributes.CssStyle[HtmlTextWriterStyle.Cursor] = "default";
    if (linkButton.Enabled != false)
    {
       linkButton.Enabled = false;
    }

    if (linkButton.OnClientClick != null)
    {
        linkButton.OnClientClick = null;
    }
}

check this also how-to-enable-or-disable-linkbutton

like image 70
PresleyDias Avatar answered Oct 05 '22 23:10

PresleyDias