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 type="button"
instead. Perhaps a better way to phrase my question would be: How do I prevent an asp button from submitting?
ASP.NET provides three types of button control: Button : It displays text within a rectangular area. Link Button : It displays text that looks like a hyperlink. Image Button : It displays an image.
Asp button works on server side while html button works on client side which is used for form validation. The html button raise click event but dosen't POST the form on clicking it while the asp button does.
You can just set UseSubmitBehavior="false"
and it will render type="button"
instead of type="submit"
(.net 4 at least)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With