ASP. net web controls are divided into two categories, respectively in the System. web. UI. webControls, System. web. UI. in the HtmlControls namespace, the former inherits from WebControl, and the latter inherits from HtmlControl. Both classes are inherited from System. web. UI. in windows, No matter what development you are engaged in, someone needs to call loadlibrary. dll.
Therefore, no matter what controls you use for ASP. net web controls, you must call Render.
In fact, as a front-end development, most of these controls are not so easy to use.
1. first, a long and long ID will be generated, especially when the surface page is embedded with controls. First, it will make your final HTML code expand. In addition, it will be 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 problem of ID conflict. 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 the 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, form has a problem during URL rewriting. The generated path is not the URL redirection path. The server needs to rewrite 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 HTML tags, however, there are no options or attribute settings at all, either for you or for all. although we can be like asp, and ASP. NET.
WebControl also brings some flexibility. Currently, ASP. NET web development is basically divided into N-layer architecture. If the code is output at the logic layer, it cannot be changed without modifying the source code, Connection textFor example, you can simply modify the attributes such as the link text template. in addition, it is quite convenient to use the table control to edit data in the background. however, it is used in front-end, GridView and other designs to form a cut-down graph, which is absolutely physical.
Some people use ASP. net web controls to quickly become obsessive-compulsive, and the front-end simple display must use the GridView. It is clear that StringBuilder is simple and efficient.
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 what's going on for a long time, later, I accidentally found that all the Image controls were automatically added with style = "border-width: 0px;". Okay, the Image at the back stage. 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, it is probably to solve the problem of the default 1 px border marked by img in the mark, but it cannot be used to process the border attribute of the Image with css.
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. When an event is triggered for an Html form control, the browser processes it. However, for a Web control, an event is generated only by the browser, but the browser does not process it. 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.
This article is from Xiaoxiao's blog garden article "web control reviews under asp.net"
- ASP. NET static page generation and paging implementation
- Use Spring to solve ibatis multi-data source troubles
- ASP. NET front-end controls comment: Avoid obsessive-compulsive disorder and rush to simple and efficient
- Some basic knowledge about ASP. net mvc Framework
- ASP. net mvc application Execution Process Analysis