Asp button with a different type of button

Is it possible to have an asp button that does not display with the type="submit" tag. I do not want the button to submit the form, so I would like to use it as type="button" . Perhaps the best way to formulate my question is: How do I prevent an asp button from being sent?

+6
button
source share
5 answers

If you do not want the button to be sent, do you need a button at all? In the end, he does nothing until he returns to the server. You can also use <input type="button" .

As the saying goes, you can use javascript to prevent postback:

 <asp:Button runat="server" OnClientClick="return false;" /> 
+1
source share

You can simply set UseSubmitBehavior="false" and it will display type="button" instead of type="submit" (.net 4 at least)

+29
source share

Using attribute UseSubmitBehaviour = "false" solved my problem

 <asp:Button ID="button1" runat="server" UseSubmitBehavior="false" Text="just a button" /> 

This attribute is available since .Net v2.0 for more information: Button.UseSubmitBehavior Property

+7
source share

Two ways:

1) Add an OnClientClick property that returns false.

  <asp:Button runat="Server" ONClientClick="return true"/> 

2) Or use the HTML ie control:

  <input type="button" id="testButton" value="Regular Button" runat="server"/> 
+3
source share

You need to prevent postback when clicking <asp:Button>

check this

+1
source share

All Articles