Although Web controls and Html controls have many similar functions and look similar, their internal implementation mechanisms are completely different.
Web controls perform better than Html controls
1. They are also quite convenient to use. Here is a simple example, such as the generation of Button:
The Html control puts all the huge collection of controls into the page. Which function is used, just set the properties, as follows:
<input type=submit/button runat=server>
This will occupy a considerable amount of control resources.
Web controls are integrated into single functions:
<asp:button id="btnOK" />
This can save resources occupied by unnecessary controls.
2. Web controls have a callback function and can use ViewState to maintain the state of the control.
The Html control cannot. When the page operation is clicked, its state will be lost.
You can do an experiment like this:
I. Create two files respectively: a.html b.aspx
II. Add the RadioButton of the Html control and a button to the a.html page.
Add the RadioButton of the Web control and a button in b.aspx
III.a.html is run directly by double-clicking the browser, and b.aspx is run through IIS.
IV. In the a.html running interface, select RadioButton, and then click the Button button. You will find that RadioButton will
Uncheck (lose its state), but perform the same operation on the b.aspx page, the RadioButton will not be lost because the ViewState
The status is saved for it. You can click "View" -> "Source File" on the browser menu in the run interface to open the Html code file.
Find the encrypted ViewState, similar to the following:
<input type="hidden" name="_VIEWSTATE" value="dDw0ajfmafmjfzzmj4"/>
In fact, the implementation principle of ViewState is to put some information into a hidden control, and the ViewState information generated by asp.net
is stored on the client
One thing to note here is:
The loopback function can only be turned on when the format is an *.aspx file and the control has the attribute: "runat=server"
3. The biggest difference between Html controls and Web controls is their different methods of event processing. For Html form control,
When an event is raised, the browser handles it. But for Web controls, the event is only generated by the browser, but the browser will not process it. The client needs to send a message to the server to tell the server to handle the event. However, some events
for example:
Events such as key press/move/mouse etc., these events are not available in Asp.net
(Because these events are highly immediacy, the server cannot process them promptly enough.) At this time, the Html control comes into play, combined with Html events
to help complete the process.
The following are some commonly used events in Html:
Html control event executed on the browser:
triggered when clicked:
<INPUT type="button" value="Click Me" onclick="alert('Hi, Hello!');">
Triggered when the mouse bounces:
<INPUT type="button" value="Click Me" onmouseup="alert('Hi, Hello!');">
//Triggered when hovering above the control
<INPUT type="button" value="Click Me" onmouseover="alert('Hi, Hello!');">
//Triggered when the mouse moves above the control
<INPUT type="button" value="Click Me" onmousemove="alert('Hi, Hello!');">
//Triggered when the control is double-clicked
<INPUT type="button" value="Click Me" ondblclick="alert('Hi, Hello!');">
//When the focus is on the control, it triggers when the key is pressed
<INPUT type="button" value="Click Me" onkeypress="alert('Hi, Hello!');">
//Triggered when the key is pressed
<INPUT type="button" value="Click Me" onkeydown="alert('Hi, Hello!');">