Disable the postback on an

前端 未结 17 1576
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 00:18

I have an ASP.NET linkbutton control on my form. I would like to use it for javascript on the client side and prevent it from posting back to the server. (I\'d like to use t

17条回答
  •  执念已碎
    2020-12-03 01:10

    ASPX code:

    
    

    Code behind:

    public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            someID.Attributes.Add("onClick", "return false;");
        }
    }
    

    What renders as HTML is:

    clicky
    

    In this case, what happens is the onclick functionality becomes your validator. If it is false, the "href" link is not executed; however, if it is true the href will get executed. This eliminates your post back.

提交回复
热议问题