Literal control doesn't have CssClass property?

  • Thread starter Thread starter George Jordanov Ivanov
  • Start date Start date
G

George Jordanov Ivanov

All,

Today I was playing with Literal control. Basically it is more or less like
the Label control with this difference that Literal control is something
like "lightweight" text container (that is it doesn't have any server side
functionality like responding to events, etc.). Now the thing that prevents
me from using it, is the fact that I can't assign CSS class to it. Do you
guys know why is that, why I can't set the CSS class directly to this
control? If can't do this, I have to go with Label control only for this
difference, but this will make my server side page rendering heavier.

Regards,
George Jordanov Ivanov
 
For applying a css class, the output of the literal control must have a
wrapping element like <span>bla bla</span>. As the purpose of the
Literal control is to do not supply any output but what the user puts in
the Text property, it cannot be relied upon that it will contain a valid
wrapping element.

btw. Using labels does not make the rendering time of your asp.net page
significant longer.

--
Ward Bekker
"Asp.Net Discussions for the Professional Developer"
http://www.dotnettaxi.com

"Free .Net 2.0 C# to/from VB.Net Code Converter"
http://www.dotnettaxi.com/Tools/Converter.aspx
 
IIRC it doess't assign a CSS class because it doesn't write any tags
out. It's not much of a container, it's just a placeholder Where do you
want the CSS class to be written to?

If you need to dynamically set the CSS of a span, you can always run
that at server and declare it in your code as an HtmlContainerControl.
 
The whole point of the Literal controls is that it outputs static text, as
opposed to an html control. You can't assign style to it in the same way as
you can't attach style to static text in html. If you care so much about
having a lite server side, write your page in html and just add runat=server
to the controls that you want to see on server.

Eliyahu
 
The literal control, literally displays what is stored in the text property.
Therefore if you want to apply css styles to the text you have to set the
text property to the HTML that you would use in a static web page to achive
the style you want. The literal control is for doing what it's name says,
displaying literal text with no filtering or modification at all.
 
Back
Top