arkitrave log

arkitrave :: log

9/11/2005

Literally not a label

Filed under:

When building pages that utilize JavaScript which will be implemented into a .NET framework, be sure to tell the developer (or if you’re like me, do it yourself) to use <%asp:literal%> tags rather than <%asp:label%> tags for database-driven content. .NET will automatically add <span> tags to anything inside a label, whereas a literal will be implemented as pure data from whatever data source you are using. The problem is that developers are trained to use the label, rather than the literal, so they won’t do this on their own.

The literal preserves the integrity of your HTML, the label does not. If you’re writing a script that, say, swaps out an image caption in a paragraph, dynamically writing that paragraph’s firstChild node value, you will run into problems if an additional span tag, inserted by .NET, appears inside that paragraph. The script will, of course, find the span tag and identify it, rather than the text node you were going for, as the firstChild.

Don’t let .NET write your code. If you’re a front-end web designer, learn enough about the framework your designs will be implemented in to know how to keep them from being messed up by the backend. I’ve learned my lesson, and was able to help a developer better understand the impact of his code choices on the front end. Now I’ll (hopefully) get asp:literals every time.

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.