Literal vs. LiteralControl vs. Label

G

Guest

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,
 
K

Kevin Spencer

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

Mr Newbie

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

Bruce Barker

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)
 
G

Guest

Thank you. Now I get it.
--
Joe

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


Bruce Barker said:
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)
 
K

Kevin Spencer

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.

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 said:
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)
 
K

Kevin Spencer

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 said:
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.
 
Joined
Dec 11, 2008
Messages
1
Reaction score
0
Kevin Spencer said:
>
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?
[/color]

I'm pretty sure "this" is referring to the sentence not in parenthesis "They meant to be used as a caption for controls".

From the context of the rest of his post it's likely he thinks Label is a design flaw because Label is already a standard for HTML and having the same name used for ASP.NET in a somewhat connected purpose is confusing being that HTML works so closely with ASP.NET.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top