Literal control doesn't have CssClass property?

  • Thread starter George Jordanov Ivanov
  • 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
 
W

Ward Bekker

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
 
F

Flinky Wisty Pomm

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.
 
E

Eliyahu Goldin

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
 
G

Guest

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.
 
Joined
Sep 13, 2006
Messages
1
Reaction score
0
The Literal Escence

The importance of Literal, beyond performance, is that you can write html formatted text (i.e. A paragrpah with <br> and stuff like this... have u tried to make a line change in a label containing lots of text and needing to be formatted?) in a more controllable way than using, in instance Response.Write.

Thus, you put the literal control wherever you want and control some behavior over it.

Sadly, style controlling is not available for this control. But is logic u need to have control of this aspect. A simple way to do this, is make the Literal be part of a Panel. The panel will acept the css property and the Literal, will inherit this appearence.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top