Conceptual differences between ASP controls and HTML controls _ practical Tips

Source: Internet
Author: User
First of all, let's talk about the difference between the two concepts (I believe we all know)

1. An ASP control is a server-side control, and HTML is a client control.

2. When the ASP control resolves at the server side, it translates into an HTML control that enables the client browser to be displayed. That means the final product is HTML control.

3. asp controls can only be resolved by installing the. NETFramework server, and HTML is java,php,asp.

So let's say the difference between the two functions

1. The ASP control must be submitted by the page (unless forced to cancel, see 2.), and HTML controls can be committed or not committed (set by the Type property)

2. asp control onclick and OnClientClick difference: OnClientClick Execution Client Event response (by JavaScript control); onclick executes the server-side event response.

Priority of both: OnClientClick > OnClick.

Examples of both exist in ASP controls:
Copy Code code as follows:

<asp:button id= "Btndel" width= "80px" cssclass= "ButtonStyle" runat= "server" text= "delete" onclientclick= "return Jsdel () ;" onclick= "Btndel_click1"/>

Note that when we hit this button, the client is automatically executed first and then the server side is executed. If the client returns false, then the server-side corresponding method will never be executed. This will achieve detection, only through the implementation of server-side methods.

Which means if we write:
Copy Code code as follows:

<asp:button id= "Btndel" width= "80px" cssclass= "ButtonStyle" runat= "server" text= "delete" onclientclick= "Jsdel (); return false; onclick= "Btndel_click1"/>

So no matter how the knot Jsdel executes. The server-side corresponding Btndel_click1 method will never be executed. Because return false makes the client always returns false

If we write:
Copy Code code as follows:

<asp:button id= "Btndel" width= "80px" cssclass= "ButtonStyle" runat= "server" text= "delete" onclientclick= "Jsdel ();" onclick= "Btndel_click1"/>

Then the btndel_click1 will happen. And that's not going to work. That means you don't have to pass the test to do the server's way. So you have to pay attention.

3. The onclick of an ASP control differs from the onclick meaning of an HTML control: The former is responded by a server-side event and the other by the client.

4. HTML controls, when added runat= "Server", are essentially the same as ASP controls (which are now converted to server-side controls), and the server can respond to HTML controls.

5. The property keywords in HTML controls are lowercase. So we should pay attention to these details, small control will also have great research, and b/s development than C/s itself has complexity, a lot of details are not the same.

We know that the server control, in the ID will add a series of other parameters:

Similar:
Copy Code code as follows:

<asp:checkboxlist runat= "Server" id= "Chktrainconfirmtype" repeatdirection= "horizontal" style= "Display:none" >
</asp:CheckBoxList>

And on the server side performance:

Ctl00_contentmain_chktrainconfirmtype

And we're going to manipulate these controls on the client, and the call ID has the following methods:

1. Run Page view source copy ID//non-fetch
2.document.getelementbyid ("<%=buttn.") Clientid%> ")//only on the page JS code to get JS file inside can not get//buttn and the following txt1 are the ID of the control
3. In the background registration method to all the required ID when the parameters passed in
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.