Controls in asp.net fall into two categories:
System. Web. UI. WebControls
System. Web. UI. HtmlControls
In a namespace, the former inherits from WebControl, and the latter inherits from HtmlControl. Both classes are inherited from System. Web. UI. Control.
Windows platform, No matter what development you are engaged in, eventually someone needs to call loadlibrary. dll.
The asp.net control, no matter what control you use, will eventually call Render.
In fact, as a front-end development, most of these controls are not so easy to use.
1. The first step is to generate a long and long ID, especially when the surface is embedded with controls. First, it will make your final HTML code
Expansion, in addition, it is difficult to work with js. to interact with js, you need to write a bunch of <% = Control. clientID %>, no way. asp.net must be 'loan' to help us solve the ID conflict
The problem. Why is this ID not separated from the final generated ID? It may be that javascript was not as powerful as it was at the time of this control, and it was ignored by ms.
2. There is also the issue of generating more than one span, that is, it is not w3c, and is not conducive to the layout. When writing css, consider the span in the middle.
3. form problems, many forms and other controls need to use the form on the server. When there are multiple forms, some of them can only be interacted with js, when the form URL is rewritten
There is another problem. The generated path is not the URL redirection path. The server needs to rewrite the form for processing.
4. For new users, there is still a long _ VIEWSTATE
Many times, when writing the front-end code, we only need to simply present it, without a long ID, span, _ VIEWSTATE, and just a few lines of clean code.
HTML tags, but there are no options or attribute settings at all, either for you, or for all. Although we can write code like asp, and asp.net, since we provide
Always used.
WebControl also brings some flexibility. Currently, asp.net web development is basically divided into N-layer architecture. If these codes are output at the logic layer,
You cannot change the source code without modifying it. For example, <asp: HyperLink runat = "server" ID = "link"> connection text </asp: HyperLink>, simple change of connection text
Template and other attributes. In addition, it is quite convenient to use the table control to edit data in the background, but it is also very convenient to use it in front-end, the GridView and so on to be designed as a beautiful cut-down graph, which is absolutely physical.
Some people are almost obsessive when using controls. The simple display on the front-end must use the GridView. Is it concise and efficient to use StringBuilder.
A few days ago, I encountered a strange problem. I wanted to make an effect, move the mouse over the image, highlight the border, and add it to the code. It didn't work. I don't know how to get it back for a long time.
Later, I accidentally discovered all the Image controls. I automatically added style = "border-width: 0px;". Okay, the background is the Image. attributes. remove ("style ");
There is still style = "border-width: 0px;" added with Image. attributes. clear (); there is still style = "border-width: 0px;", which is definitely a brainless design, probably
Solve the Problem of marking the default 1 px border by img in the mark, but there is no way to use css to process the border attribute of the Image.
My most commonly used controls:
Literal is clean and convenient. HTML code and js Code are pieced together.
Repeater clean list
Placeholder control display logic
The most brainless controls:
For the Image reason, see the preceding
The least valuable controls:
Label span sets literal, and the style is handed over to the artist to solve the problem. It cannot be seen any practical value.
Difficult controls:
Datalist, the layout of div or list generated by gridview is very tired (only the front-end)
The field of view varies with other controls.
In addition, the difference between HtmlControl and WebControl is that it is misleading to say so on the Internet. It cannot be seen anymore. Let's explain it.
--------------------------------
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/text runat = server>
This will occupy a considerable amount of control resources
--------------------------------
This is purely misleading and widely spread. in the end, HTML tags are generated. The combination of input and other components does not need to be merged into the page, but only generates a tag, it is only the difference between the HtmlControl and WebControl base classes.
--------------------------------
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.
--------------------------------
Protected virtual void LoadViewState (object savedState );
Protected virtual object SaveViewState ()
In fact, these two definitions are defined in System. web. UI. in the Control base class, only WebControl overwrites the two methods, but HtmlControl does not overwrite the two methods, but this does not mean that
--------------------------------
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.
--------------------------------
This obfuscated server events and client script events. Both self-WebControl and HtmlControl can trigger Server events.
To process server events, you only need to implement the IPostBackEventHandler interface control.