We know that making a control is generally more complicated than a module that only implements the same function, because we need to consider more exceptions and adaptability to achieve the effect of integrating and reusing code. And when we develop an ASP.NET control, no matter how complex the functions and UI performance of our control are, what we end up getting in the client browser is just a combination of HTML code and scripts.
As for the HTML codes generated by these controls, can their formats be processed at will? So what does it mean to not be free? Do we have to ensure the formatting of HTML code and maintain good hierarchical indentation of HTML? On the contrary here, we should try to remove anything that has nothing to do with the HTML code of the control, including "useless" spaces and carriage returns. Why emphasize the useless? We know that when the browser processes the HTML source code, consecutive spaces and carriage returns are processed and displayed as one space. Therefore, it seems that we don't need to care about the extra useless spaces or carriage returns before, after, or in the middle of the HTML code when the ASP.NET control is rendered. So 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>
'www.downcodes.com
The above code snippet is the HTML code output by the Web Chart control in Dundas Web Controls. There seems to be no problem when using this Chart image with a hot area. If you just use this Chart alone, there is indeed no problem. But when we combine Dundas Chart into a custom WebControl, its HTML code with line breaks and indentation causes problems. Due to layout needs, I need to put this Chart into a table and have the table display a pixel border closely surrounding the Chart. Originally, the appearance of this Chart was just a picture, and there seemed to be no problem with this combination. However, the actual situation is that the picture of the Chart could never fill up the outside table (as shown below), and there were always gaps at the bottom of the picture and the bottom edge of the table. There is a gap of 3-4 pixels. This gap is caused by the space and line break between <img /> and <map> (although IE only treats it as a space).
|
Since Dundas Web Chart is a released compiled dll, it becomes more troublesome to delete useless spaces and carriage returns in the HTML it outputs. We can only take out the HTML code from its Render stream, then manually remove the spaces and carriage returns between tags, and then output it to the output stream of the new control. Although this method can solve some problems, if the internal controls are too complex, it will be an extra burden in terms of accuracy and efficiency.
So from the above questions we can see that when we make an ASP.NET control, the HTML code that is finally rendered should follow the "code compactness principle" to improve the adaptability of the control. Under this principle the previous example should look like this:
<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 adjacent to the table border surrounding it.