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)