Difference between the types of buttons

Asked

Viewed 1,770 times

5

What is 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, matter of events, manipulation, effects while clicking.

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

2 answers

7


  • <input type="button" /> is the primitive DOM type of interface. In HTML5 it was replaced by the element HTMLButtonElement.
  • <button></button>, or HTMLButtonElement, is the HTML5 version. It may be of the type button, reset or submit.
  • <input type="submit" /> (and his brother reset) are derivations of the element button. Certain behaviors are associated by default:
    • <input type="submit" /> sends the form in the context of which the element exists;
    • <input type="reset" /> returns the fields present for their original values.
  • <asp:button> is not an HTML element. It is an abstraction of the ASP.NET platform to allow integration between environments client- and server-side. The Renderer generates an element <input type="button" />, but when this is clicked a javascript event is intercepted and a call is submitted to the application, which results in the event invocation server-side linked.
  • right, but in the case of onsubmit being an event JS it works on the 3 components?

  • 1

    According to the documentation (https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onsubmit), yes - as long as you do not call the form function directly (form.submit(););

4

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


This:

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

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>

Will be rendered like this:

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.