【问题标题】:How to completely disable the link button? [duplicate]如何完全禁用链接按钮? [复制]
【发布时间】:2012-03-13 11:09:54
【问题描述】:

可能重复:
Disabling LinkButton doesn't disable the click event in javascript

我在 ASP.NET 中有一个链接按钮。

我已经设置了它的属性 Enabled = false;

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

事件以为我设置了Enabled = false属性,OnClientClick事件仍然被触发。

如何防止OnClientClick 事件触发?

【问题讨论】:

标签: asp.net


【解决方案1】:

这是来自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;
    }
}

也检查一下how-to-enable-or-disable-linkbutton

【讨论】:

    【解决方案2】:

    在页面加载中你可以这样写:

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

    【讨论】:

      猜你喜欢
      • 2017-11-03
      • 1970-01-01
      • 1970-01-01
      • 2021-11-08
      • 1970-01-01
      • 1970-01-01
      • 2018-02-08
      • 2012-02-01
      • 2012-04-21
      相关资源
      最近更新 更多