ASP. NET front-end controls comment: Avoid obsessive-compulsive disorder and rush to simple and efficient

Source: Internet
Author: User

ASP. NET foreground controls Overview

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.

ASP. NET foreground controls

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 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 write code like asp and asp.net, since it is provided, it is 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, they cannot be changed without modifying the source code. <asp: hyperLink runat = "server" ID = "link"> connection text </asp: HyperLink> for example, you can easily modify attributes such as the connection 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 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 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.

ASP. NET front-end controls

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.

This article is from windinwing's blog: web control reviews under asp.net.

  1. ASP. NET Server Control View
  2. ASP. NET DataGrid Control Data grouping operation
  3. ASP. NET Component Design-Analysis of ASP. NET Timer
  4. ASP. NET Server Control
  5. Introduction to ASP. NET Custom Controls

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.