Disable the postback on an

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

    Just been through this, the correct way to do it is to use:

    1. OnClientClick
    2. return false

    as in the following example line of code:

    <asp:LinkButton ID="lbtnNext" runat="server" OnClientClick="findAllOccurences(); return false;" />
    
    0 讨论(0)
  • 2020-12-03 00:47

    Something else you can do, if you want to preserve your scroll position is this:

    <asp:LinkButton runat="server" id="someId" href="javascript: void;" Text="Click Me" />
    
    0 讨论(0)
  • 2020-12-03 00:51

    This may sound like an unhelpful answer ... But why are you using a LinkButton for something purely client-side? Use a standard HTML anchor tag and set its onclick action to your Javascript.

    If you need the server to generate the text of that link, then use an asp:Label as the content between the anchor's start and end tags.

    If you need to dynamically change the script behavior based on server-side code, consider asp:Literal as a technique.

    But unless you're doing server-side activity from the Click event of the LinkButton, there just doesn't seem to be much point to using it here.

    0 讨论(0)
  • 2020-12-03 00:58

    Just set href="#"

    <asp:LinkButton ID="myLink" runat="server" href="#">Click Me</asp:LinkButton>
    
    0 讨论(0)
  • 2020-12-03 00:58

    call java script function on onclick event.

    0 讨论(0)
  • 2020-12-03 00:59

    I think you should investigate using a HyperLink control. It's a server-side control (so you can manipulate visibility and such from code), but it omits a regular ol' anchor tag and doesn't cause a postback.

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