Web controls and HTML controls have the same functions and look very similar. However, their internal implementation mechanisms are completely different. Web controls are more efficient than HTML controls.
1. It is quite convenient to use. For example, button generation: The HTML control gets a huge set of controls to the page. If you use this function, set the attributes as follows: <Input type = submit/button runat = Server> This will occupy a considerable amount of control resources
Web controls are integrated into a single function: <Asp: button id = "btnok"/> This saves the resources occupied by unnecessary controls.
2. The web control has the send-back function, which can be used to maintain the control state with viewstate. The HTML control is not available. When you click the page, its status will be lost. You can do this experiment: I. Create two files respectively: a.html B. aspx Ii.add the radiobutton and a button of the HTML control on the.html page, Add the radiobutton and a button of the Web Control in B. aspx. Iii.a.html directly double-click the browser to run, B. aspx runs through IIS Iv.in the.html running interface, select radiobutton and click the button. Then, radiobutton will Deselect (lose its status), but do the same operation on the B. ASPX page, radiobutton will not be lost because viewstate You can click "View"-> "source file" in the browser menu on the running interface to open the html Code File, Find the encrypted viewstate, which is 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
Is stored on the client Note that: The send-back function can be enabled only when the format is *. aspx and the control has the property "runat = server ".
3. The biggest difference between HTML controls and Web controls is that they have different processing methods for events. For HTML form controls, When an event is triggered, the browser will handle it. However, for Web controls, events are only generated by the browser, but browsing The client sends a message to the server telling the server to process the event. But some events, For example: Events such as pressing the key, moving, and mouse do not exist in Asp.net. (Because these events are highly real-time, and the server cannot process them in a timely manner), the HTML Control plays its role in combination with HTML events.
Assistance.
The following are common HTML events: HTML control event executed on the browser:
Triggered upon clicking: <Input type = "button" value = "Click me" onclick = "alert ('Hi, hello! '); ">
Triggered when the mouse is started: <Input type = "button" value = "Click me" onmouseup = "alert ('Hi, hello! '); ">
// Triggered when suspended above the control <Input type = "button" value = "Click me" onmouseover = "alert ('Hi, hello! '); ">
// Triggered when the cursor 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! '); ">
// Triggered when the focus is on the Control <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! '); "> When you do not need to interact with the background, you can use the HTML control. It consumes less resources and is fast. When you need to interact with the background, you can use the web control, you can also add runat = "server" to the HTML control to convert an HTML control to an interactive control. However, the resources occupied by the control are no different from those occupied by the web control. The web control can respond to server events and SET related properties and methods in the background code! HTML is not allowed. Web server controls need to be processed by the server and then translated into HTML controls and sent to the browser. Therefore, server resources are consumed and iewstate exists, therefore, when sending a message back, the control status is maintained (or you can set it to not save it), which increases the amount of information sent back. HTML is directly sent to the browser, which does not consume server resources, but is saved stateless! To obtain the value of an HTML control, you need to use the form method of the request. The web control can be processed directly through attributes! Therefore, in general, HTML can be used for dynamic processing of controls without the need to save the control status and without any value processing, or you can save the status of the Web server control! Web server controls are easy to use, but they consume more server resources! Many books have said that when considering performance, you should try not to use web server controls. When to use it, you don't have to look at the specific situation, but when the conditions are loose, it depends on your habits. The difference is that if the server control has runat = server, HTML is not necessary, and Web is a waste of resources. Sender: chrisjiang HTML space is the client. web space is the server. Sender: luckyfool . Net has many HTML controls and can also be runat = Server The key is whether you need to conveniently obtain the value in the CS file. Sender: uglyuugly Microsoft recommends webcontrol, Htmcontrol is used for porting ASP code. |