ASP 101 - Active Server Pages 101 - Web03
The Place ASP Developers Go!



Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash



 Top ASP 101 Stories Top ASP 101 Stories
Connections, Commands, And Procedures
What is ASP?
VBScript Classes: Part 1 of N

QUICK TIP:
Start Optimizing Where It Matters Most
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates


Quick Tips


Use the Literal Control for Precise Rendering

While ASP.NET server controls make developing Web pages much simpler, sometimes they don't output their HTML exactly the way you'd like them to. That's where the Literal Web server control comes in. Unlike most other controls, it doesn't add anything to the output.

Think about that for a second. Basically, the Literal control does nothing for us. So... why would you want to use it?

You use the Literal control when you want precise control over the HTML or text that is sent to the browser. Many developers tend to use a Label control in situations when they should probably be using a Literal control. The Label control works great when you're actually trying to label something, but the problem with using it in other situations is that, the Label control actually renders a span element around its content. In addition to adding to size of the resulting page, the span element can actually interfere with a page's existing styles. The Literal control doesn't add any HTML or text to the output. That way there's nothing to interfere with you getting the page to look exactly the way you want.

At its most basic, a literal control looks something like this:

<asp:Literal id="litExample" runat=server />

and unless you assign a value to its Text property (either declaratively or via code), the control won't render anything at all.

For more information on the Literal Web server control, check out the documentation on MSDN:


Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers