Differences between asp controls and html controls

Source: Internet
Author: User

First, let's talk about the differences between the two concepts (I believe everyone knows)

1. asp controls are server controls and html controls are client controls.

2. After the asp control is parsed on the server, it is converted to an html control so that the browser on the client can display it. That is to say, all the final products are html controls.

3. asp controls can only be parsed by the server where. netFrameWork is installed, while html can be parsed using Java, php, and asp.

The following describes the differences between the two functions.

1. The asp control must be submitted on the page (unless it is forcibly canceled, see 2.), while the html control can be submitted or not submitted (set through the type attribute)

2. Differences between the asp control OnClick and OnClientClick: OnClientClick executes the client Event Response (controlled by JavaScript); OnClick executes the server event response.

Priority: OnClientClick> OnClick.

Examples of asp control:
Copy codeThe Code is as follows:
<Asp: Button ID = "btnDel" Width = "80px" CssClass = "buttonstyle" runat = "server" Text = "delete" OnClientClick = "return jsDel (); "OnClick =" btnDel_Click1 "/>

It should be noted that when we click this button, the client automatically runs first and then the server. if the client returns false, the corresponding method on the server will never be executed. in this way, the server-side method is executed only when the detection succeeds.

That is to say, if we write:
Copy codeThe Code is as follows:
<Asp: Button ID = "btnDel" Width = "80px" CssClass = "buttonstyle" runat = "server" Text = "delete" OnClientClick = "jsDel (); return false; "OnClick =" btnDel_Click1 "/>

No matter how jsDel is executed, the btnDel_Click1 method corresponding to the server will never be executed. Because return false makes the Client Always return false.

If we write:
Copy codeThe Code is as follows:
<Asp: Button ID = "btnDel" Width = "80px" CssClass = "buttonstyle" runat = "server" Text = "delete" OnClientClick = "jsDel (); "OnClick =" btnDel_Click1 "/>

BtnDel_Click1 may occur, but it will not be able to achieve the same effect. That is to say, if you do not pass the detection, you can also execute the server method. Therefore, you must pay attention to it.

3. The OnClick of the asp control is different from the OnClick of the html control. The former is returned by the server event, and the latter is returned by the client.

4. After the html control is added with runat = "server", it is basically the same as the asp control (now converted to a server control), and the server can respond to the html control.

5. Attribute keywords in the html control must be in lowercase. So everyone should pay attention to these details. Some small widgets will also be asked by the university, and B/s development is more complex than c/s development itself, and many details are not the same.

We know that the server control will add a series of other parameters to the id:

For example:
Copy codeThe Code is as follows:
<Asp: CheckBoxList runat = "server" ID = "chkTrainConfirmType" RepeatDirection = "horizontal" style = "display: none">
</Asp: CheckBoxList>

On the server side:

Ctl00_ContentMain_chkTrainConfirmType

To operate these controls on the client, call the id using the following methods:

1. Run the page to view the source code copy ID // not available
2.doc ument. getElementById ("<% = buttn. clientID %> ") // It can only be obtained from the js file in the js Code on the page. // both buttn and txt1 are the control IDs.
3. register all the required IDs in the background as parameters.
Button1.Attributes ["click"] = "Button_click (" + txt1.ClientID + "," + txt1.ClientID + "," + txt. ClientID + ");";

Related Article

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.