Conceptual differences between asp controls and html controls

  • 2020-12-20 03:32:18
  • OfStack

First of all, let's talk about the conceptual difference between the two.

1. asp control is a server-side control, while html is a client-side control.

2. After the asp control is parsed by the server, it will be converted to html control so that the client browser can display it. In other words, the final product is the html control.

asp control only installed.netFrameWork server can be resolved, and html with Java,php,asp can be.

So the following two functional implementation differences

1. asp controls must be committed (unless cancellation is enforced, see 2.), and html controls can or cannot be committed (set by the type property)

2. Difference between OnClick and OnClientClick: OnClientClick performs client event response (controlled by JavaScript); OnClick performs server-side event response.

Priority for 2: OnClientClick > OnClick.

For example, when two of them coexist in asp control:
<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, it automatically executes the client side first and then the server side. If the client returns false, the corresponding method on the server side is never executed. This achieves detection by only executing server-side methods.

In other words, if we write it as:
<asp:Button ID="btnDel" Width="80px" CssClass="buttonstyle" runat="server" Text=" delete " OnClientClick="jsDel(); return false;" OnClick="btnDel_Click1" /> 

So whatever the knot that jsDel performs. The corresponding btnDel_Click1 method on the server side is never executed. Because return false causes the client to always return false

If we write:
<asp:Button ID="btnDel" Width="80px" CssClass="buttonstyle" runat="server" Text=" delete " OnClientClick="jsDel();" OnClick="btnDel_Click1" /> 

So btnDel_Click1 is going to happen. Nor does it work. In other words, you can no longer execute server methods without passing detection. So you have to be careful.

3. The OnClick of asp control is different from the OnClick of html control: the former is responded by the server event, while the latter is responded by the client.

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

5. html control property keywords should be lowercase. So pay attention to these details, small controls will also be asked, and b/s development is more complex than c/s development itself, many details are not quite the same.

As we know, server controls, in id will add 1 series of other parameters:

Similar to:
<asp:CheckBoxList runat="server" ID="chkTrainConfirmType" RepeatDirection="horizontal" style="display:none"> 

On the server side:


To manipulate these controls on the client side, call id as follows:

1. Run the page to view the source code copy ID // is not advisable
2.document.getElementById(" < %=buttn.ClientID% > ") // Only on the page js code access js file can not access //buttn and txt1 below are control id
3. In the background registration method, all the required ID are passed in as parameters
Button1.Attributes["click"] = "Button_click(" + txt1.ClientID + "," + txt1.ClientID + "," + txt.ClientID + ");";

Related articles: