Difference between button types

5

What's the difference between the following components?

<button type="button">Click Me!</button>
<asp:button ID="cmdAvancar" runat="server" >Click Me!</asp:button>
<input type="submit" value="Submit">

I say for example in properties, events, manipulation, click effects.

For example if I need to use the onsubmit event of Javascript all 3 will work?

    
asked by anonymous 09.02.2017 / 19:02

2 answers

7
  • <input type="button" /> is the primitive DOM type of the interface . In HTML5 it has been replaced by the HTMLButtonElement element.
  • <button></button> , or HTMLButtonElement , is the HTML5 version. It can be of type button , reset or submit .
  • <input type="submit" /> (and its reset brother) are derivations of the button element. Certain behaviors are associated by default:
    • <input type="submit" /> sends the form under whose context the element exists;
    • <input type="reset" /> returns the present fields to their original values.
  • <asp:button> is not an HTML element. It is an abstraction of the ASP.NET platform to allow integration between the client and server-side environments. The renderer generates a <input type="button" /> element, but when it is clicked a javascript event is intercepted and a call is submitted to the application, which results in the invocation of the server-side event bound.
09.02.2017 / 19:36
4

Button ( asp:button ) will be rendered in HTML as <input type="submit"> or as <button> . This will depend on the defined properties.

This:

<asp:button ID="cmdAvancar" runat="server" >Click Me!</asp:button>

It will be rendered like this:

<input name="cmdAvancar" type="submit" value="Click Me" />

This

<asp:button ID="cmdAvancar" runat="server" UseSubmitBehavior=false >Click Me!</asp:button>

It will be rendered like this:

<button name="cmdAvancar" type="button">Click Me!</button>

In the Button (asp: button) you can use the OnClientClick property to program onclick (JavaScript). Also you have the event OnClick so that when clicked a Code-Behind event is executed.

    
09.02.2017 / 19:30