ASP. NET Control Learning Summary

Source: Internet
Author: User

ASP. NET controls are divided 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. So ASP. NET control, no matter what control you are using, 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 'login' 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 ASP. NET controls:
◆ Literal clean and convenient. Splice HTML code and js Code
◆ Repeater clean list
◆ Placeholder control display logic

The most brainless controls:
◆ For the Image reason, see the preceding article

The least valuable controls:
◆ The label span is set to 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:

 
 
  1. <input type=submit/button/text runat=server>  

This will occupy considerable ASP. NET 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. You can use ViewState to maintain the status of the control. The Html control cannot. When you click a page, its status will be lost.

 
 
  1. protected virtual void LoadViewState(object savedState);  
  2. 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-side script events. Both WebControl and HtmlControl can trigger Server-side events to process server-side events. You only need to implement the IPostBackEventHandler interface control.

  1. ASP. NET static page generation and paging implementation
  2. Use Spring to solve ibatis multi-data source troubles
  3. ASP. NET front-end controls comment: Avoid obsessive-compulsive disorder and rush to simple and efficient
  4. Some basic knowledge about ASP. net mvc Framework
  5. ASP. net mvc application Execution Process Analysis

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.