If you have attended to yesterday (4th September
2008) Joy’s session in CDNUG monthly meeting, you may heard about Best Practices
in developing Web Parts. Yes, as a one point he clearly mentioned that not use
HTML tags directly in Web Part’s rendering. Here I am going to add something by
showing how to write out proper HTML in Web Parts.
What will happen if I write the code like above? Nothing, it
will work properly as long as HTML is correct. Then, what is the sense? Fine… these are the point to say that is not
good.
- Yes, I know you can write minimum code with first approach. But is it readable? Noh... Actually it is not.
- It is not maintainable code. Just think you want to add another row for HTML table. Then you have to check each HTML tag to find the exact position.
- Error prone. For an example if you mistakenly forget to put HTML close tag, then it will affect to whole page that web part is running. And also, it may affect to another web part in your page or syndication generation.
If you check the below code, you can understand the difference.
I know it may take little bit of your
time. But end of the day you have well written peace of code. Maintainability, fine
HTML, etc... Everything is there…