user366312
user366312

Reputation: 17026

How can I block postback caused by an ASP.NET Button?

How can I block postback caused by an ASP.NET Button (or, any other) server control?

I.e. I shall push a Button but no postback will occur.

Upvotes: 0

Views: 1960

Answers (5)

Thorarin
Thorarin

Reputation: 48516

You can make the client side validation fail for the control's validation group. Depending on what you're trying to do, that might be a nicer solution.

You can piggyback on the JavaScript run for each postback as well, but showing you from the top of my head while typing on a mobile phone... maybe not. I'll update this post when I get home.

Upvotes: 0

JB King
JB King

Reputation: 11910

You could use AJAX controls that do callbacks instead of postbacks for another possibility besides the Javascript "return false;" answer.

Upvotes: 0

Max
Max

Reputation: 2581

<asp:button runat="server" ... OnClientClick="return false" />

Upvotes: 0

Gavin H
Gavin H

Reputation: 10502

you could use the

OnClientClick="return false;"

property of the button

Upvotes: 2

Eric
Eric

Reputation: 8088

do this

button.Attributes.Add("onclick", "return false;")

on page load.

Upvotes: 3

Related Questions