Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Literal vs. LiteralControl vs. Label

Reply
Thread Tools

Literal vs. LiteralControl vs. Label

 
 
=?Utf-8?B?Sm9l?=
Guest
Posts: n/a
 
      11-11-2005
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
 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      11-11-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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



 
Reply With Quote
 
 
 
 
Mr Newbie
Guest
Posts: n/a
 
      11-11-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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



 
Reply With Quote
 
Bruce Barker
Guest
Posts: n/a
 
      11-11-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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



 
Reply With Quote
 
=?Utf-8?B?Sm9l?=
Guest
Posts: n/a
 
      11-11-2005
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >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

>
>
>

 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      11-12-2005
> 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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

>
>



 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      11-12-2005
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" <(E-Mail Removed)> wrote in message
news:eG7u$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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

>
>



 
Reply With Quote
 
feddas feddas is offline
Junior Member
Join Date: Dec 2008
Posts: 1
 
      12-30-2008
Quote:
Originally Posted by Kevin Spencer
>
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Set formatting (color) on a literal or label =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= ASP .Net 2 03-09-2006 09:39 PM
What's wrong with rpc-literal? Why use doc-literal? Anonieko Ramos ASP .Net Web Services 0 09-27-2004 09:06 AM
LiteralControl thread safety. George Ter-Saakov ASP .Net 1 04-06-2004 10:06 AM
Difference between UI.LiteralControl and WebControls.Literal ? Andreas Klemt ASP .Net Web Controls 3 01-04-2004 11:28 AM
What is the difference between LiteralControl and Literal ? Andreas Klemt ASP .Net 1 01-03-2004 04:28 AM



Advertisments