473,396 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Literal vs. LiteralControl vs. Label

Joe
I know that the Literal control will not render a <span> tag so I can not
format its text. Other than this, what is the difference betwen the Literal
control and the LiteralControl Control? How about a LiteralControl and a
Label?

Other than the lack of being able to format the Literal control's text, I
don't see much of a difference in the documentation.

TIA,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
Nov 19 '05 #1
6 6904
A Literal Control is a Literal. A Label has specific properties that a
Literal does not.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Complex things are made up of
Lots of simple things.

"Joe" <jo******@donotspam.yahoo.com> wrote in message
news:C9**********************************@microsof t.com...
I know that the Literal control will not render a <span> tag so I can not
format its text. Other than this, what is the difference betwen the
Literal
control and the LiteralControl Control? How about a LiteralControl and a
Label?

Other than the lack of being able to format the Literal control's text, I
don't see much of a difference in the documentation.

TIA,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation

Nov 19 '05 #2
Your confusing me.

The Literal control will render anything you tell it to.
Protected WithEvents Literal1 As System.Web.UI.WebControls.Literal

sub page_load

Literal1.text = "<SPAN style="color=blue">My Text Is Blue</SPAN>"

end sub
Labels are just that, they label things.

--
Best Regards

The Inimitable Mr Newbie º¿º
"Joe" <jo******@donotspam.yahoo.com> wrote in message
news:C9**********************************@microsof t.com...
I know that the Literal control will not render a <span> tag so I can not
format its text. Other than this, what is the difference betwen the
Literal
control and the LiteralControl Control? How about a LiteralControl and a
Label?

Other than the lack of being able to format the Literal control's text, I
don't see much of a difference in the documentation.

TIA,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation

Nov 19 '05 #3
the LiteralControl is part of the base web.ui class. it allows simple output
of text

the Literal control is part of the WebControls namespace which is MS
abstracted web controls. these controls all support binding and viewstate.
this control if viewstate is turned on, will remember its properties across
a post back, unlike the above control. neither of these controls outputs
anything but the text (no tags)

the Label control is a design error by MS. its a Literal with a span so you
can apply a style to it. they meant to be used as a caption for controls
(because you can set a style). but you should not do this.

there is a real html <label> control, and section 508 compliance
(disabilities act requires this for any gov html site) requires every form
input control have a label with it "for" attribute identifying the matching
input control. this requirement is to support text readers. a simple form
should be coded as

<form id=runat=server>
<label for=textbox1>input name:</label>
<asp:textbox id=textbox1 runat=server />
<asp:button runat=server id=button1 text=submit>
</form>

the "for" attribute on the label should be the id of the input control for
which its the label. this becomes important if the table is used to align
the content as they are no longer adjacent.

while its easy to type in the id this case, if you use a template, or the
input control in in user control, the actual id render is not the one you
typed but rathe the UniqueId. this now means you have to set the "for"
attibute in the codebehind, a real pain. i wrote my own caption class to get
around this.
-- bruce (sqlwork.com)


"Joe" <jo******@donotspam.yahoo.com> wrote in message
news:C9**********************************@microsof t.com...
I know that the Literal control will not render a <span> tag so I can not
format its text. Other than this, what is the difference betwen the
Literal
control and the LiteralControl Control? How about a LiteralControl and a
Label?

Other than the lack of being able to format the Literal control's text, I
don't see much of a difference in the documentation.

TIA,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation

Nov 19 '05 #4
Joe
Thank you. Now I get it.
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Bruce Barker" wrote:
the LiteralControl is part of the base web.ui class. it allows simple output
of text

the Literal control is part of the WebControls namespace which is MS
abstracted web controls. these controls all support binding and viewstate.
this control if viewstate is turned on, will remember its properties across
a post back, unlike the above control. neither of these controls outputs
anything but the text (no tags)

the Label control is a design error by MS. its a Literal with a span so you
can apply a style to it. they meant to be used as a caption for controls
(because you can set a style). but you should not do this.

there is a real html <label> control, and section 508 compliance
(disabilities act requires this for any gov html site) requires every form
input control have a label with it "for" attribute identifying the matching
input control. this requirement is to support text readers. a simple form
should be coded as

<form id=runat=server>
<label for=textbox1>input name:</label>
<asp:textbox id=textbox1 runat=server />
<asp:button runat=server id=button1 text=submit>
</form>

the "for" attribute on the label should be the id of the input control for
which its the label. this becomes important if the table is used to align
the content as they are no longer adjacent.

while its easy to type in the id this case, if you use a template, or the
input control in in user control, the actual id render is not the one you
typed but rathe the UniqueId. this now means you have to set the "for"
attibute in the codebehind, a real pain. i wrote my own caption class to get
around this.
-- bruce (sqlwork.com)


"Joe" <jo******@donotspam.yahoo.com> wrote in message
news:C9**********************************@microsof t.com...
I know that the Literal control will not render a <span> tag so I can not
format its text. Other than this, what is the difference betwen the
Literal
control and the LiteralControl Control? How about a LiteralControl and a
Label?

Other than the lack of being able to format the Literal control's text, I
don't see much of a difference in the documentation.

TIA,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Nov 19 '05 #5
> the Label control is a design error by MS. its a Literal with a span so
you can apply a style to it. they meant to be used as a caption for
controls (because you can set a style). but you should not do this.
A <span> tag is *not* a Literal Control with a <span> tag, any more than any
other System.Web.UI.WebControls Control is a Literal Control with any other
kind of tag. The Label Control inherits
System.Web.UI.WebControls.WebControl, while the Literal Control inherits
System.Web.UI.Control, which means that the only thing they have in common
is the System.Web.UI.Control class.

I'm curious as to why you think that creating a Control for a <span> is a
design error. You provided no foundation for this statement.
they meant to be used as a caption for controls (because you can set a
style). but you should not do this.
Here I'm confused, as you make 2 different statements, and conclude with 1
that says "you should not do this." Which of the 2 is "this?" Do you mean
you should not use a Label as a caption for a Control? If so, why? Do you
mean that you should not apply a style or a CSS class to a <span> tag? If
so, why not?

The following CSS Level 1 specification from the W3C.org web site lists all
of the standard CSS properties, and the types of elements they apply to:

http://www.w3.org/TR/REC-CSS1-961217.html

In fact, it provides several examples using <span> tags for text formatting.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
There's a seeker born every minute.
- Dr. "Happy" Harry Cox

"Bruce Barker" <br******************@safeco.com> wrote in message
news:OI**************@TK2MSFTNGP09.phx.gbl... the LiteralControl is part of the base web.ui class. it allows simple
output of text

the Literal control is part of the WebControls namespace which is MS
abstracted web controls. these controls all support binding and viewstate.
this control if viewstate is turned on, will remember its properties
across a post back, unlike the above control. neither of these controls
outputs anything but the text (no tags)

the Label control is a design error by MS. its a Literal with a span so
you can apply a style to it. they meant to be used as a caption for
controls (because you can set a style). but you should not do this.

there is a real html <label> control, and section 508 compliance
(disabilities act requires this for any gov html site) requires every
form input control have a label with it "for" attribute identifying the
matching input control. this requirement is to support text readers. a
simple form should be coded as

<form id=runat=server>
<label for=textbox1>input name:</label>
<asp:textbox id=textbox1 runat=server />
<asp:button runat=server id=button1 text=submit>
</form>

the "for" attribute on the label should be the id of the input control for
which its the label. this becomes important if the table is used to align
the content as they are no longer adjacent.

while its easy to type in the id this case, if you use a template, or the
input control in in user control, the actual id render is not the one you
typed but rathe the UniqueId. this now means you have to set the "for"
attibute in the codebehind, a real pain. i wrote my own caption class to
get around this.
-- bruce (sqlwork.com)


"Joe" <jo******@donotspam.yahoo.com> wrote in message
news:C9**********************************@microsof t.com...
I know that the Literal control will not render a <span> tag so I can not
format its text. Other than this, what is the difference betwen the
Literal
control and the LiteralControl Control? How about a LiteralControl and a
Label?

Other than the lack of being able to format the Literal control's text, I
don't see much of a difference in the documentation.

TIA,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Nov 19 '05 #6
Just to clarify Mr. N's remarks, a Label Control renders a <span> tag and
it's text contents, while a Literal Control only renders the text you put
into it. The Label Control has properties that enable one to programmtically
control certain attributes, like the CSS class of the <span> tag. The
Literal Control's only controllable aspect is the text that it holds.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
There's a seeker born every minute.
- Dr. "Happy" Harry Cox

"Mr Newbie" <he**@now.com> wrote in message
news:eG**************@tk2msftngp13.phx.gbl...
Your confusing me.

The Literal control will render anything you tell it to.
Protected WithEvents Literal1 As System.Web.UI.WebControls.Literal

sub page_load

Literal1.text = "<SPAN style="color=blue">My Text Is Blue</SPAN>"

end sub
Labels are just that, they label things.

--
Best Regards

The Inimitable Mr Newbie º¿º
"Joe" <jo******@donotspam.yahoo.com> wrote in message
news:C9**********************************@microsof t.com...
I know that the Literal control will not render a <span> tag so I can not
format its text. Other than this, what is the difference betwen the
Literal
control and the LiteralControl Control? How about a LiteralControl and a
Label?

Other than the lack of being able to format the Literal control's text, I
don't see much of a difference in the documentation.

TIA,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dale zhang | last post by:
Hi, I have a web form page. it has gridlayout and a table at top like a template. When I have the literal or requiredfieldvalidator ErrorMsg displayed, they are all over the page. Is there...
1
by: Andreas Klemt | last post by:
Hello, what is the main difference between Literal and LiteralControl? Thanks in advance Andreas
1
by: James Newton-King | last post by:
I was wondering if a literal store information in the viewstate? Does anyone know?
3
by: VB Programmer | last post by:
What's the real advantage to using a literal control over a simple label? What are the pros/cons/typical usages for the literal control? Thanks.
2
by: David Thielen | last post by:
We have a status message we display that can be good news (in green) or bad news (in red). Is there a way to do this for a single literal or label? Or do we need to have two, one set to green and...
2
by: David Thielen | last post by:
Hi; I have some error messages I have to create (can't use the validators). I have done this using both labels and literals - is there any reason to prefer one over the other? Note: We are...
5
by: paul.hester | last post by:
Hi all, I have a custom control with an overridden Render method. Inside this method I'm rendering each control in its collection using their RenderControl method. However, I'm running into a...
0
by: shapper | last post by:
Hello, I want to create a control which is based in Literal control. I created various properties. Size, Name, City, etc. Basically, I want the Text of the literal control to be equal to Size...
4
by: Scott M. | last post by:
I'm not sure where I should be placing the code that creates my literal controls. They are rendering but AFTER the close of the HTML tag. I've tried Load, Init, PreLoad, PreInit, PreRender and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.