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?
Have you tried to use the
OnClientClick
?You can do it too
And it stop the link button postback
In the jquery ready function you can do something like below -
Something else you can do, if you want to preserve your scroll position is this:
You might also want to have the client-side function return false.
You might also consider:
I use the clickable class to set things like pointer, color, etc. so that its appearance is similar to an anchor tag, but I don't have to worry about it getting posted back or having to do the href="javascript:void(0);" trick.
ASPX code:
Code behind:
What renders as HTML is:
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.