If you need to be able to update the text displayed in an ASP.net control such as a LinkButton through code-behind before the page is rendered but will end up using that control to invoke client-side javascript and don’t want a PostBack to happen you can simply add “return false;” after your custom JavaScript calls in the OnClientClick event handler of the control. “return false;” actually stops the page from posting back to the server and allows your custom JavaScript to be run client-side.
Example:<asp:LinkButton ID="lbtnVisit" runat="server" Text="» Default Text" OnClientClick="CustomScriptMethod(); return false;">
Excelente tip!!
Thanks.
LikeLike
nice tip. Helped me a lot. I was trying to stop postback from linkbutton if a field entry was not valid. This gave me the idea –
OnClientClick=”return (ValidateInput())”
// ValidateInput must return true/false. Of course true will do the postback.
LikeLike
Hi,
Thanx for this nice answer. I appriciate it. 🙂
LikeLike
its a simple and great response. thank you very much
LikeLike
This would not work… bcoz this renders as … so whether u return true or false it would always return and would never go to __doPostBack. I faced this for long and realized that the correct way was onClientClick= “if (!ValidateInput()) return false”
This would return only when ValidateInput returns false else it would go to the next line i.e __doPostBack…
Here check this http://deeps-space.blogspot.com/2010/05/stopping-postback-on-client-side-with.html
LikeLike
thnx a lot
LikeLike
Thnaks for the tip, works a treat!
LikeLike
Thanks alot
LikeLike