The difference and use of HTMLControl and WebControl

Source: Internet
Author: User
Tags html form html page interface client
web| difference

Web controls and HTML controls are as good and versatile as they look.

But their internal implementation mechanism is completely different.

Web controls perform better than HTML controls

1. It is also quite handy to use, for example, a button is generated:

HTML control is a huge collection of controls to all of the page, which function to use, set the properties, as follows:

<input Type=submit/button runat=server>

This takes up a significant amount of control resources

A Web control is a single feature that integrates the disassembly of an integrated solution:

<asp:button id= "Btnok"/>

This saves the resources that are used by unnecessary controls.

The 2.Web control has a loopback capability to maintain the state of the control with viewstate.

HTML controls cannot, and when clicked on the page, their status is lost.

You can do one of these experiments:

I. Two documents were established: a.html b.aspx

Ii. Add the HTML control's RadioButton and a button to the A.html page,

Add a RadioButton and a button to the Web control in b.aspx

iii.a.html directly double-click the browser to run, b.aspx run through IIS

Iv. in the A.html run interface, select RadioButton, click the button button, and you will find that RadioButton

Uncheck (lose its state), but do the same on the B.aspx page, RadioButton will not be lost because ViewState

Saved the state for it. You can click on the browser menu "view"-> "source file" in the Run interface, 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 also put some information into a hidden control, and asp.net generated viewstate information

is stored in the client's

The point to note here is:

The loopback feature can be turned on only if the format is a *.aspx file and the control has properties: "Runat=server"

3. The biggest difference between HTML controls and Web controls is that they differ in how the event is handled. For HTML form controls,

When an event is raised, the browser handles it. However, for Web controls, events are generated only by the browser, but browsing

Device does not process it, the client sends a message to the server telling the server to handle the event. But some events,

Like what:

Press the key/move/mouse events, asp.net no these events

(Because these events are quick and the server is not processed in time), HTML controls play their part, combining HTML events

Assistance to complete.

The following are some common HTML events:

HTML control events executed on the browser:

triggered when clicked:

<input type= "button" value= "click Me" >

Trigger when mouse is bouncing:

<input type= "button" value= "click Me" >

Triggered when hovering over a control

<input type= "button" value= "click Me" >

Triggered when the mouse moves above the control

<input type= "button" value= "click Me" onmousemove= "alert (' Hi, hello! ');" >

Trigger when double-clicking a control

<input type= "button" value= "click Me" ondblclick= "alert (' Hi, hello! ');" >

When the focus is on the control, the key is triggered

<input type= "button" value= "click Me" onkeypress= "alert (' Hi, hello! ');" >

Trigger when Press pressed

<input type= "button" value= "click Me" >







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.