I wish to put some instructions with a link - onclick calling a script that display a simple alert box. If I did like this...
<label for="arquivo">Máximo de 1MB, observe os <a href="" onclick="ajudaUpload();">tipos permitidos</a>.</label>
the page is reloaded even with a return false, and if I did like this...
<label for="arquivo">Máximo de 1MB, observe os <a href="#" onclick="ajudaUpload();">tipos permitidos</a>.</label>
with the "#" symbol, the page is scrolled to the top and "#" is added to query string. Is there a third way to do it without reloading, scrolling and garbage?
If you want to avoid full page refresh, then don't use UpdatePanel control as it will only give more pain the butt. Instead, use AJAX with client-side grid (e.g jQuery grid, Webgrid, etc) and handle everything at the client (JavaScript code).
If you put # inside the href like <a href="#"></a> then the link will not refresh or reload when clicked.
Use the preventDefault() method on the event object to prevent a page refresh on form submit in React, e.g. event. preventDefault() . The preventDefault method prevents the browser from issuing the default action which in the case of a form submission is to refresh the page.
Return false after the call:
<a href="" onclick="ajudaUpload();return false;">tipos permitidos</a>
Or if your function returns false then you can return the result of the function:
<a href="" onclick="return ajudaUpload();">tipos permitidos</a>
It's not enough to just return false in the function, you need to actually return false from the click handler.
You can use .preventDefault()
method, or return false, or remove the HREF tag all together. Either should work just fine.
Vc nao deviar estar usando onclick
dessa forma pra comecar. Ja eh bem antigo e nao se usa assim mais.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With