Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp button with different button type

Tags:

button

asp.net

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?

like image 437
Radu Avatar asked Jan 05 '11 20:01

Radu


People also ask

What are different types of button control?

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.

What is the difference between the Web server button control and the HTML submit button?

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.


2 Answers

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

like image 115
Robert Ivanc Avatar answered Nov 15 '22 23:11

Robert Ivanc


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

like image 22
Ricky Avatar answered Nov 15 '22 21:11

Ricky