asp:Label rendering as <span> in IE :(

G

garthb

Hello,

I have a site which I've been developing locally with VS2k3 Pro. I
have some browsercap information in my web.config to help identify
Firefox as an upscale browser. It works great locally. Labels render
as labels and so on.

However, when deploying the site onto a different server, all my Labels
render as <spans>, even in IE. I don't understand what's going on, I
haven't had this happen to me before. What discrepencies between the
configuration of IIS (or whatever) could exist between my local machine
and the server? As far as I can tell, I've copied everything over to
the server including the web.config with the browsercap info. I might
have expected this to happen with Firefox if I failed to update the
remote web.config, but the fact it's happening with IE is totally
stumping me.

Any ideas as to what's going on?

The Labels render as <span AssociatedControlID="foo">bar</span>. The
local development machine is XP Pro SP2 and the server is Win2k SP4.

Thank you for any advice!

Garth
 
G

garthb

Peter, thank you for your response!

Shouldn't Labels render as <label>s if an associated control ID is set?
That's the behaviour I'm used to. The form this is a part of requires
the semantics of a <label> to achieve the required degree of
accessibility.

Anyone else have any suggestions?

Thank you,
Garth
 
N

Nathan Sokalski

I want to second what you were told the first time, that IE always renders
Labels as Span tags, I don't think I've ever seen them rendered as anything
else. I think that Label Controls are rendered as <span> tags because they
are more generic, therefore allowing ASP.NET to more easily make them look
the way you designed them (this is why you don't see ASP.NET creating tags
such as h1, h2, h3, etc.). If you want a Control to be rendered as a
specific HTML tag, my recommendation would be to create a UserControl that
uses Controls from the System.Web.UI.HtmlControls namespace. I haven't seen
your exact code, so I don't know why you need the code to generate <label>
tags, but in my opinion it is better to stick with <span> because I think it
is more widely supported. Also, if your code "requires" <label> tags (or any
other specific tag), I would recommend looking it over because it sounds
somewhat inefficient, and if you are preventing yourself from using the
built-in Controls such as Label, you will be putting yourself through a lot
of extra work to get less productive results. Good Luck!
 
G

garthb

The merits of using <label>s versus other less "inefficient" tags is a
discussion for another forum, but in the context of this thread I guess
I'm going to have to find another way to generate them. Here is
something interesting I found on MSDN.

===========
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.label.associatedcontrolid.aspx):

When the AssociatedControlID property is set, the Label control renders
as an HTML label element, with the for attribute set to the ID property
of the associated control. You can set other attributes of the label
element using the Label properties. For example, you can use the Text
and AccessKey properties to provide the caption and hot key for an
associated control.
===========

The HUGE caveat here is that this page also says it's "new for .Net
2.0"!! I do have 2.0 installed on my machine, but I expected VS2k3 to
continue using 1.1. The easy fix for me to try here, then, is to
install 2.0 on the server...

Thanks for everyones input!

Garth
 
G

garthb

To close off this thread, I discovered that even though my local
website definition in IIS is set to use .Net 1.1, it's using 2.0. I
verified this by installing 2.0 on the server. The installation of 2.0
didn't solve my problem until I set the website to actually use 2.0,
then Labels rendered as <labels>.

In other words, other than my local IIS apparently not doing what it
should, everything is working as it is supposed to, including have
Label's rendering as <span>s in 1.1 and having them render as <label>s
in 2.0.

Thanks again to Peter and Nathan for kicking me in the right direction!

Garth
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top