Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting style for Label element 1

Status
Not open for further replies.

Gill1978

Programmer
Joined
Jun 12, 2001
Messages
277
Location
GB
Hi All,

I'm trying to add the CssClass property on an <asp:Label> element. However the class that i've set up is not working

The .css file has the following code:
Code:
label.header
{
	background-color : Red;
	font-family : MS Sans Serif;
	font-size : 2px	

}

The html code has the following:

Code:
        <asp:Label
            CssClass="header" 
            ID="Label1" 
            runat="server"
            Text="Test 1">
        </asp:Label>

Can anyone see what i'm doing wrong here???

Thanks in advance,

Julie
 
I'll need to do some asp reading to explain why an <asp:label> tag translates into Span tag in html ... because thats logical?!!?
More likely because ASP is a heap of ...

I suppose, to be fair, it's just trying to hide the underlying complexity of HTML, so programmers can say make a field based on this value, label it like this, and it just happens. That's fine, but you're stuck with the best way the language developers knew to do that task when they wrote it - which may not be the current best practice.

In this case, it's really weird because the HTML <label> element is no more complex than the asp one:
Code:
<label id="Label1" class="header" for="xxx">Test 1</label>
The [tt]for="xxx"[/tt] adds some useful functionality. If you give the <input> you're labelling an [tt]id="xxx"[/tt], clicking on the label causes the cursor to appear in the input (or a checkbox to change value, or whatever). That's assuming that's what an asp:label is used for, btw.

Don't worry, you're not the first person to post server-side code when posting a query on this site (nor will you be the last, dammit!). Just remember that when your ASP (or PHP, or CF, or whatever) program has done it's thing, what ends up going to the browser is (X)HTML. That's the code that the browser will try to interpret, and that's what you/we need to look at to debug it.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Actually, the reason why there is such a thing as asp:Label and why it is named label instead of span is because MS truly expects you to use it as a Label. There is no hard rule that says .Net will render that asp:Label as a span tag, though I haven't seen it render otherwise.
One of the ideas behind .Net is that you could use the controls they provide that have been extended in the .Net libraries to do common tasks, then the .Net engine would render the controls however it see's fit to the browser that happens to be querying for the page. The idea here is that this will allow for better browser support across the board without having to learn the behaviour of each browser. So IE6 is supplied with HTML4 comliant HTML and most other browsers are supplied with HTML 3.4 :P

This also exposes another danger in using tag names in your CSS when using ASP.Net. You cannot guarantee that asp:Label will always be rendered as a span (maybe IE7 will use labels?), therefore it is easier to assume nothing and use the classname or id.


Oh, and I am not an ASP.Net expert, but I am an expert at finding dang near every flaw in it, including magic breakpoints in non-existant magic byte code in between functions.

 
I have to give them credit, there is a good reason for this. The idea is to produce content that comes the closest to what you designed in Visual Studio for all browsers, including that browser 3 versions back that is a couple standards back and doesn't support tags/standards that the newer ones do. Now, as always, MS took some shortcuts and screwed some things up, but 2005 defaults to XHTML but should still provide proper code to older browsers as HTML 4/3.4/whatever. The idea being to give a browser the standards it can handle.

The two largest places they screwed up (IMO):
1) They waited until 2005 to offer XHTML
2) They defaulted a bunch of 4.01 and XHTML compliant browsers to 3.4 (Like FF)

2 Can definately be changed in the .Net settings, not sure about 1 (in 2003 and 2002).

 
Because all of the other options were less interesting? :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top