Literal vs. LiteralControl vs. Label

Discussion in 'ASP .Net' started by =?Utf-8?B?Sm9l?=, Nov 11, 2005.

  1. 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
     
    =?Utf-8?B?Sm9l?=, Nov 11, 2005
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    >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
     
    Kevin Spencer, Nov 11, 2005
    #2
    1. Advertising

  3. =?Utf-8?B?Sm9l?=

    Mr Newbie Guest

    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" <> wrote in message
    news:...
    >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
     
    Mr Newbie, Nov 11, 2005
    #3
  4. =?Utf-8?B?Sm9l?=

    Bruce Barker Guest

    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" <> wrote in message
    news:...
    >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
     
    Bruce Barker, Nov 11, 2005
    #4
  5. 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" <> wrote in message
    > news:...
    > >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

    >
    >
    >
     
    =?Utf-8?B?Sm9l?=, Nov 11, 2005
    #5
  6. > 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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    >>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

    >
    >
     
    Kevin Spencer, Nov 12, 2005
    #6
  7. 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" <> wrote in message
    news:eG7u$...
    > 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" <> wrote in message
    > news:...
    >>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

    >
    >
     
    Kevin Spencer, Nov 12, 2005
    #7
  8. =?Utf-8?B?Sm9l?=

    feddas

    Joined:
    Dec 11, 2008
    Messages:
    1
    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.
     
    feddas, Dec 30, 2008
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    1
    Views:
    1,562
    Showjumper
    Jan 3, 2004
  2. George Ter-Saakov

    LiteralControl thread safety.

    George Ter-Saakov, Apr 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    336
    Martin Dechev
    Apr 6, 2004
  3. Andreas Klemt

    Difference between UI.LiteralControl and WebControls.Literal ?

    Andreas Klemt, Jan 3, 2004, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    680
    Alessandro Zifiglio
    Jan 4, 2004
  4. Anonieko Ramos

    What's wrong with rpc-literal? Why use doc-literal?

    Anonieko Ramos, Sep 27, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    380
    Anonieko Ramos
    Sep 27, 2004
  5. Knut Krueger
    Replies:
    8
    Views:
    280
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page