Special ASPX or HTML tags?

2

I'm starting to design websites with asp.net in c #, so from the toolbox I have the graphic components as if I were designing a desktop app. When I drag a button, the code shows me:

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

I can also put buttons with an html tag:

<button></button>

Is there a difference? Which one would you recommend me to use? Thanks.

    
asked by dr4kxn355 01.08.2016 в 16:57
source

2 answers

0

The difference is that the <asp:Button> is a Web Server Control

ASP.NET Server Controls

instead if <button> or <input type="button"> is only html

If you define <button runat="server"> would be an Html Control, in this case it would be a HtmlButton

HTML Controls for ASP.NET Web Pages

The web control and html control have events to the server, while the html do not have them, for this you must use javascript or jquery sending the data by ajax with json format

If you are going to program using asp.net use the Web Server Control or be <asp:Button> since you will have the events.

Now if the idea is to go to asp.net MVC in that case if you would use html controls.

    
answered by 01.08.2016 / 17:35
source
3

The ASP% <asp:Button> button is a server control that is not only available on the client side, but also to which you can access from the server side using its ID. Instead a <button> is an HTML control that shows a button whose scope is limited to the client side.

Another difference is that <asp:Button> causes the form to be sent with a POST every time you click on it ( postback ), something that does not happen when using <button> .

The recommendation on which one to use will depend on what you want to use them for. If you want the button just to do some kind of validation / logic on the client side, use <button> ; if you want the button to do some operation on the server side, use <asp:Button> .

    
answered by 01.08.2016 в 17:19