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:
- <img id="analysisChart" src="ChartPic_000007.
jpeg?B9FA64E7-2020-4430-AAF4-B20A51794909" usemap="#usemap_analysisChart">
- <map id="usemap_analysisChart">
- <area>...<area>
- </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:
- <img id="analysisChart" src="ChartPic_000007.jpeg?B9FA64E7-2020-4430-AAF4-B20A51794909"
- usemap="#usemap_analysisChart"><map
- id="usemap_analysisChart"><area>
- ...
- <area></map>
In this way, the Chart image is closely tied to the border of the table surrounding it.
- Microsoft released multiple function updates for ASP. net mvc 2 preview Edition
- ASP. NET Server custom control security guidelines
- Analysis of ASP. NET programming standards and Their encoding specifications
- Introduction to ASP. NET sessions
- ASP. NET programming tool ASP. NET Web Matrix