HTML code of the ASP. NET Control

Source: Internet
Author: User

We know that creating a control is generally more complicated than simply implementing modules with the same function, because we need to consider more exceptions and adaptability to achieve our ability to integrate and reuse code. When we develop an ASP. NET controls, no matter how complex the functions and UI of our controls are, what we get in the client browser is a combination of HTML code and scripts.

The HTML code generated by these controls can be processed in any format. So what does it mean not to be random? Do we have to ensure the HTML code layout and maintain a good level of HTML indentation? On the contrary, we should try to remove anything irrelevant to the control HTML code, including "useless" spaces and carriage return. Why emphasize useless? We know that when processing HTML source code, the browser processes and displays consecutive spaces and carriage returns with a single space. Therefore, it seems that we do not care about ASP. NET controls in the Render, HTML code before and after or in the middle of the useless spaces or carriage return. Let's take a look at the following example:

 
 
  1. <img id="analysisChart" src="ChartPic_000007.
    jpeg?B9FA64E7-2020-4430-AAF4-B20A51794909" usemap="#usemap_analysisChart"> 
  2. <map id="usemap_analysisChart"> 
  3. <area>...<area> 
  4. </map> 

The above code snippet is the HTML code output by the Web Chart control in Dundas Web Controls. The Chart image with hot area does not seem to have any problems in use. If you use this Chart separately, it is indeed no problem. However, when we combine Dundas Chart into a custom WebControl, this HTML code with line breaks and indentation will cause problems. Due to layout requirements, I need to put this Chart into a table and let the table display a pixel border Closely surrounding the Chart. The appearance of this Chart is just an image. It seems that there should be no problems with such a combination, but the actual situation is that the picture of that Chart cannot be filled with external tables, there is always a 3-4 pixel gap between the bottom of the image and the bottom of the table. This gap is caused by the empty space and line feed between and <map> (although IE is only used as a space.

Because Dundas Web Chart is a released compiled dll, It is troublesome to delete unnecessary spaces and press enter in the HTML output by Dundas. We can only extract the HTML code from its Render stream, manually remove the spaces and carriage return between tags, and then output the code to the output stream of the new control. Although this method can solve some problems, if the internal control is too complicated, it will be an extra burden in terms of correctness and efficiency.

Therefore, we can see from the above question that when we create an ASP. NET control, the final HTML code should follow the "Code compact principle" to improve the adaptability of the control. In this principle, the previous example should be as follows:

 
 
  1. <img id="analysisChart" src="ChartPic_000007.jpeg?B9FA64E7-2020-4430-AAF4-B20A51794909" 
  2. usemap="#usemap_analysisChart"><map 
  3. id="usemap_analysisChart"><area>
  4. ...
  5. <area></map> 

In this way, the Chart image is closely tied to the border of the table surrounding it.

  1. Microsoft released multiple function updates for ASP. net mvc 2 preview Edition
  2. ASP. NET Server custom control security guidelines
  3. Analysis of ASP. NET programming standards and Their encoding specifications
  4. Introduction to ASP. NET sessions
  5. ASP. NET programming tool ASP. NET Web Matrix

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.