Plip's Weblog

Phil Winstanley - British Microsoft ASP.NET MVP & ASP Insider.

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.

 

Posted: May 01 2006, 04:25 PM by Plip | with 13 comment(s)
Filed under:

Comments

foobar said:

Why would I want to do this? The Label control literally is that - a label for something (usually a form control). The attribute AssociatedControlID allow me to attach the label to another control. Very handy for things like checkboxes and radio buttons so that they behave more like client-UIs.

If you need to spit out <p>'s, you can use the PlaceHolder control.
# May 1, 2006 11:47 AM

Phil Winstanley said:

foobar,

Two things: -

1. It's just me showing off the Adapter Framework ;-) I wasn't seriously suggesting using it! :-)

2. I believe the PlaceHolder renders nothing, and the Panel renders <div> tags.
# May 1, 2006 11:58 AM

Shane Porter said:

There's nothing wrong with the <p> tag either Phil; in fact it's quite a nice little tag.

Line breaks <br /> are a bad thing anyway most of the time. Better to control spacing with padding and margin in your CSS for your <p>s.
# May 16, 2006 2:38 PM

ass traffic said:

All about ass traffic

# November 19, 2006 4:10 PM

britney spears pregnant photos said:

More or less nothing seems important. So it goes. Oh well. It's not important. That's how it is.

# December 6, 2006 4:54 AM

Jesse Capelli said:

Jesse Capelli and Adriana Sage

# December 8, 2006 10:31 AM

pantieless mardi said:

More or less nothing seems important. It's not important. Shrug. Whatever. I've just been hanging out doing nothing, but eh. I can't be bothered with anything lately.

Estou no ltimo ano de Design na faculdade de belas artes de lisboa, mas, embora no tenha nada a ver com o curso que estou a tirar, tenho uma grande paixo pela biologia marinha, e j pensei vrias vezes em tirar o curso de Biologia Marinha quando acabar o que estou a frequentar. Sei que vai ser dificil mas eu estou disposta a tentar. Por issso, se tiveream alguma informao (cursos existentes em portugal ou estrangeiro, etc) que me possa ser til, agradecia que me enviassem para Muito Obrigada pela vossa ateno

Estou no ltimo ano de Design na faculdade de belas artes de lisboa, mas, embora no tenha nada a ver com o curso que estou a tirar, tenho uma grande paixo pela biologia marinha, e j pensei vrias vezes em tirar o curso de Biologia Marinha quando acabar o que estou a frequentar. Sei que vai ser dificil mas eu estou disposta a tentar. Por issso, se tiveream alguma informao (cursos existentes em portugal ou estrangeiro, etc) que me possa ser til, agradecia que me enviassem para Muito Obrigada pela vossa ateno

# December 15, 2006 7:50 AM

2002 toyota avalon said:

BahvaryKuzar 1142872 http://cars-directory.info/toyota-avalon911/2002-toyota-avalon.html 2002 toyota avalon <a href="http://cars-directory.info/toyota-avalon911/2002-toyota-avalon.html">2002 toyota avalon</a>  [URL=http://cars-directory.info/toyota-avalon911/2002-toyota-avalon.html]2002 toyota avalon[/URL] cars-directory.info/toyota-avalon911/2002-toyota-avalon.html [link=http://cars-directory.info/toyota-avalon911/2002-toyota-avalon.html]2002 toyota avalon[/link] * http://cars-directory.info/toyota-avalon911/toyota-avalon-problem.html toyota avalon problem <a href="http://cars-directory.info/toyota-avalon911/toyota-avalon-problem.html">toyota avalon problem</a>  [URL=http://cars-directory.info/toyota-avalon911/toyota-avalon-problem.html]toyota avalon problem[/URL] cars-directory.info/toyota-avalon911/toyota-avalon-problem.html [link=http://cars-directory.info/toyota-avalon911/toyota-avalon-problem.html]toyota avalon problem[/link] *

# February 9, 2007 9:41 PM

download free mp3 music said:

yamaha music greenville spartanburg south carolina <a href= http://audiolive.org/mtv-a-19/ >all the free music now</a>

[url=http://audiolive.org/mtv-a-19/]lg fusic downloading music[/url]

# December 4, 2007 11:41 PM

Mary-nl said:

<a href= http://kustur.angelfire.com >dad vail regatta</a> <a href= http://trututa.angelfire.com >ratings apartments eagle ridge alabama</a>

# November 29, 2008 2:47 AM

Mary-po said:

<a href= adultpersonalsfinder.com >dating</a>

# March 1, 2009 1:42 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)