How to completely disable the link button?

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

Method 2

In Page Load you can write following way:

page_load
{    
   if(lnkButton.Enabled)
      lnkButton.Attributes.Add("OnClientClick","Javascript");    
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x