Disable the postback on an

前端 未结 17 1493
隐瞒了意图╮
隐瞒了意图╮ 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:08

    Instead of implement the attribute:

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

    Use:

    OnClientClick="return false;"
    

    inside of asp:LinkButton tag

    0 讨论(0)
  • 2020-12-03 01:09

    Why not use an empty ajax update panel and wire the linkbutton's click event to it? This way only the update panel will get updated, thus avoiding a postback and allowing you to run your javascript

    0 讨论(0)
  • 2020-12-03 01:10

    ASPX code:

    <asp:LinkButton ID="someID" runat="server" Text="clicky"></asp:LinkButton>
    

    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:

    <a onclick="return false;" id="someID" href="javascript:__doPostBack('someID','')">clicky</a>
    

    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.

    0 讨论(0)
  • 2020-12-03 01:11

    No one seems to be doing it like this:

    createEventLinkButton.Attributes.Add("onClick", " if (this.innerHTML == 'Please Wait') { return false; } else {  this.innerHTML='Please Wait'; }");
    

    This seems to be the only way that works.

    0 讨论(0)
  • 2020-12-03 01:11

    use html link instead of asp link and you can use label in between html link for server side control

    0 讨论(0)
提交回复
热议问题