Disable the postback on an

2019-01-13 19:39发布

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 the linkbutton control so I can skin it and disable it in some cases, so a straight up tag is not preferred).

How do I prevent it from posting back to the server?

17条回答
The star\"
2楼-- · 2019-01-13 20:13

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.

查看更多
Viruses.
3楼-- · 2019-01-13 20:17

Just set href="#"

<asp:LinkButton ID="myLink" runat="server" href="#">Click Me</asp:LinkButton>
查看更多
霸刀☆藐视天下
4楼-- · 2019-01-13 20:17

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.

查看更多
ゆ 、 Hurt°
5楼-- · 2019-01-13 20:17

Just been through this before few minutes, the correct way to do it is use

  1. OnClientClick
  2. Return False()

as the following example line of code:

<asp:LinkButton ID="lbtnNext" runat="server" OnClientClick="findAllOccurences(); return false();" Visible="false"/>

Just copied that line from my working code.

查看更多
唯我独甜
6楼-- · 2019-01-13 20:18

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

查看更多
何必那么认真
7楼-- · 2019-01-13 20:21

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

查看更多
登录 后发表回答