, welcome to web design enthusiasts to web development.
Although web controls and html controls are very functional and look very similar
But their internal implementation mechanism is completely different
Web controls are more efficient than html controls
1. It is also quite convenient to use. For example, the generation of buttons:
The html control brings all the huge control collection into the page. Whenever the function is used, set the properties as follows:
<input type=submit/button runat=server>
This will take up a considerable amount of control resources
The web controls disassemble the integrated into a single function:
<asp:button id="btnok" />
This saves the resources occupied by unnecessary controls
2. The web control has a loopback function, and can use viewstate to maintain the state of the control.
The html control cannot, and when the page is clicked, its status will be lost.
An experiment like this can be done:
i. Create two files separately: a.html b.aspx
ii. Add the radiobutton and a button of the html control in the a.html page,
Add radiobutton and a button of web control in b.aspx
iii.a.html runs directly with double-click on the browser, b.aspx runs via iis
iv. In the a.html running interface, select radiobutton, and then click the button button, you will find that radiobutton will
Uncheck (lost its status), but do the same on the b.aspx page, radiobutton will not be lost because viewstate
Save the status for it. You can click "View"->"Source File" in the running 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 viewstate implementation principle is to put some information into a hidden control, and the viewstate information generated by asp.net
It is stored on the client
One thing to note here is:
The loopback function can only be turned on when the format is *.aspx file and the control has the property: "runat=server".
3. The biggest difference between html controls and web controls is that they have different methods of handling events. For the html form control,
When an event is raised, the browser processes it. But for web controls, events are generated only by the browser, but browsing
The machine will not process it, and the client needs to send a message to the server to tell the server to handle the event. But some incidents,
for example:
Press key/move/mouse and other events, these events are not available in asp.net
(Because these events are very immediacy, the server does not handle them in time), then the html control will play its role, combined with the html event
Assist in completing.
Here are some common events for html:
html control events executed on the browser:
Triggered when clicked:
<input type="button" value="click me" >
Triggered when the mouse is bounced:
<input type="button" value="click me" onmouseup="alert('hi, hello!');">
// Trigger when floating 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 double-clicking the control
<input type="button" value="click me" ondblclick="alert('hi, hello!');">
// When the focus is on the control, triggers when the key is pressed
<input type="button" value="click me" onkeypress="alert('hi, hello!');">
//Triggered when the button is pressed
<input type="button" value="click me" onkeydown="alert('hi, hello!');">