CSS Adapter Framework - Give your Labels some clout.
In the olden days I used to write my HTML with a tag that's seriously gone out of fashion, that tag was the Paragraph tag: -
<p>This is a paragraph, it even has the common courtoust you add a couple of line breaks at the end by default meaning people can read your inane rantings.</p>
ASP.NET brought the end to the Paragraph tag for many developers (with good reason I might add but that's a different story), but now ASP.NET is bringing the Paragraph tag back from the dead in the form of a Control Adapter.
This little sippet of code will allow you to render all your Labels as <p>aragraphs's instead of <span>'s.
using
System; using
System.Web; using
System.Web.UI; using
System.Web.UI.WebControls; namespace
Plipster.CssAdapters.WebControls {
public class LabelCssAdapter : System.Web.UI.WebControls.Adapters.WebControlAdapter {
protected override void Render(HtmlTextWriter writer) {
Label thisLabel = ((Label)base.Control); writer.WriteBeginTag(
"p"); if (thisLabel.CssClass != String.Empty) {
writer.WriteAttribute(
"class", thisLabel.CssClass); }
writer.Write(
">"); writer.Write(thisLabel.Text);
writer.WriteEndTag(
"p"); }
public LabelCssAdapter() {
}
}
}
<
browsers> <
browser refID="IE"> <
controlAdapters> <adapter controlType="System.Web.UI.WebControls.Label" adapterType="Plipster.CssAdapters.WebControls.LabelCssAdapter" /> </
controlAdapters> </
browser> </browsers>
Pretty cool I think you'll agree.
The adapter Framework is so powerful, I am only beggining to scrath the surface yet already I can see so many cool uses for the adapters.