0

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.

5 Answers 5

3

do this

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

on page load.

Sign up to request clarification or add additional context in comments.

Comments

2

you could use the

OnClientClick="return false;" 

property of the button

1 Comment

oops I was focused on the button. Slipped my mind that he wanted it to work for any control.
0
<asp:button runat="server" ... OnClientClick="return false" /> 

Comments

0

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

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.