Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp:literal or asp:label

Status
Not open for further replies.

rico14d

Programmer
Apr 8, 2002
135
0
0
GB
Hi,

What do people think of using the literal control instead of a label control?

Im thinking of just using the literal control as i've had a lot of grief from a customer regarding SEO and the amount of redundant HTML code that is produced in ASP.Net.

With the label control you might produce HTML like
<span id="lblTest">The text</span>

but a literal would only produce
The text

Can anyone see any problems with using the literal control over the label control?

Rich.
 
Use the Literal whenever you can since, as you've noted, it produces less html. With a Label, you get additional properties such as Font which you might want to use to set the color or make it bold programmatically.

[blue]_______________________________________[/blue]
Business Logic:"AND when tweetle beetles battle with paddles in a puddle, they call it a tweetle beetle puddle paddle battle AND..." - Dr. Suess
 
I use the literal control a lot - maybe too much, for the simple reason that you can incorporate other tags into it like so:

<script runat="server">
Sub Page_Load

myLiteral.text = "<div id=""divID"">This is myLiteral text</div>"
End Sub
</script>

<asp:literal id="myLiteral" runat="serveer" />

Very useful if you are displaying a number of divs dynamically.

A computer always does what you tell it to, but rarely does what you want it to.....
 
Thanks for your comments, i think i will start to use it instead of a label all the time.

Rich
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top