Asp. NET control Development "code compact Principle"

Source: Internet
Author: User
Tags compact net return
asp.net| Controls | Control Development    We know that making a control is generally more complex than a module that only implements the same functionality, because we need to consider more exceptions and adaptability to achieve our consolidated and reusable code. And when we develop a asp.net control, no matter how complex the functionality and UI performance of our controls, we end up with a combination of HTML code and scripting in the client browser.

And it's the HTML code that these controls generate, and their format is free to handle. So what does it mean to be free? Do we have to make sure that the HTML code is typeset and that the HTML is indented at a good level? Just on the contrary, we should try to remove anything that has nothing to do with the control's HTML code, including "useless" spaces and carriage returns. Why emphasize the futility of it? We know that when the browser is working on the HTML source code, the consecutive spaces and carriage returns are processed and displayed by a single space. So, it seems like we don't care asp.net controls at render time, before or after the HTML code, or in the middle of the extra space or carriage return. So let's take a look at the following example:
<map id= "Usemap_analysischart" >
<area>...<area>
</map>
' Www.knowsky.com
The code snippet above is the HTML code for the output of the Web Chart control in the Dundas Web controls. This chart picture with hot area does not seem to have any problem when using, if is the ordinary use this chart alone, really is no problem. But when we combine Dundas Chart into a custom WebControl, the HTML code with line-wrapping and indentation is problematic. Because of the layout needs, I need to put this chart into a table and let the table display a pixel border tightly surround chart. Originally the appearance of this chart is just a picture, such a combination seems to have no problem, but the actual situation is that chart picture can not be filled with the outside of the table (as shown below), and at the bottom of the picture and the table is always 3-4 pixels on the edge of the gap. This gap is due to the and <map> between the space and line (although IE only if it is a space) caused.

Chart Image

Because the Dundas Web chart is a compiled DLL, it can be cumbersome to remove useless spaces and carriage returns from the HTML that it outputs. We can only remove the HTML code from its render stream, and then manually remove the spaces between tags and the carriage return, and then output to the new control output stream. While such a method solves some of the problems, it is an additional burden in both correctness and efficiency if the internal controls are too complex to meet.

So from the above question we see that when we make a asp.net control, we should make the last rendered HTML code conform to the "code compact Principle" to improve the control's adaptability. In such a principle the previous example should be like this:
<map id=" Usemap_analysischart "> <area>...<area></map>
So the chart picture is close to the border with the table surrounding it.



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.