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?

2

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

but when i want to write function for click on html buttons I must write it in javaScript, yes?
@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).
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.

2 Comments

but when i want to write function for click on html buttons I must write it in javaScript, yes?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.