5

I'm learning asp.net. I have question about example buttons

I can use two types of button.

   <input id="Button1" type="button" value="button" />

or

   <asp:Button ID="Button3" runat="server" Text="Button" />

What are the main differences between the two?

nirmus
  • 4,913
  • 9
  • 31
  • 50

2 Answers2

3

One is a server control (the asp button) that when rendered on the page includes javascript that handles the postback logic, as well as being exposed to your code-behinds as a control you can address by its ID. The Html control is platform agnostic, and is rendered by your browser as just a button. That button will raise click events but will not POST your form.

davecoulter
  • 1,806
  • 13
  • 15
  • but when i want to write function for click on html buttons I must write it in javaScript, yes? – nirmus Jul 25 '11 at 09:10
  • @nirmus -- In the case of the asp control you can write it as back-end asp.net code, or front end code by including a "OnClientClick" handler in the button's declaration. In either case (asp or html), you can wire up an "OnClick" handler either in-line (thumbs down) or with jQuery (thumbs up). – davecoulter Jul 25 '11 at 09:20
1

Each click will make a round trip to server, which should not occur everytime. HTML Button is much lighter and should be used to make client - logic like client validation, run client script,etc....
ASP button will makes a POST everytime you click, html button do not.

Khoa Le
  • 372
  • 2
  • 9
  • but when i want to write function for click on html buttons I must write it in javaScript, yes? – nirmus Jul 25 '11 at 09:10
  • If your onClick function is a complicated one, you should. If it just show some links, you can do it with html only. Of course you can link a click-event with some php script file, if you want to do it. – Khoa Le Jul 25 '11 at 09:17