Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

button with no postback?

People also ask

How to prevent a button from postback?

The postback on submit button can be avoided by giving return=false in the event handler function as below.

How to disable postback on click button?

try doing <asp:button OnClientClick="yourfunction();return false;" UseSubmitBehavior="false" OnClick="btn_Click"/> When you make UseSubmitBehavior true, asp.net will add the necessary client-side script to post the submit to the server.


you need to use return false

<button onclick="printElement('content');return false">Print</button>

Add type="button" to your <button> tag like so:

<button type="button" onclick="printElement('content');">Print</button>

This answer explains the behavior.


Alter you click event as below:

<button onclick="printElement('content');return false;">Print</button>

if you don't need a post back you should use an HTML button.

in that case you don't need override the behavior to avoid the post back and it's laighter to load (it doesn't need to be worked by the server to render back the HTML)


You should just use an input button instead:

<input type="button" onclick="printElement('content')" value="Print" />

this doest NEED an form (so you can use it without) and you dont have the problem with the postback.

Hope this helps