Is it possible to have an asp button that isn\'t rendered with a type=\"submit\"
tag. I don\'t want the button to submit the form, so I\'d like to have it as
Using the 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
Two ways:
1) Add a OnClientClick property which returns false.
<asp:Button runat="Server" ONClientClick="return true"/>
2) Or use a HTML Control i.e:
<input type="button" id="testButton" value="Regular Button" runat="server"/>
If you don't want the button to submit, do you need a button at all ? After all, it doesn't do anything before it posts back to the server. You can might as well just use an <input type="button"
.
That being said, you can use javascript to prevent a postback:
<asp:Button runat="server" OnClientClick="return false;" />
You can just set UseSubmitBehavior="false" and it will render type="button"
instead of type="submit"
(.net 4 at least)
You need to prevent postback when pressing on an <asp:Button>
Check this