VS2005 and DOCTYPE in Web Forms

C

Chris Botha

I am porting an existing 2003 project to 2005. Yesterday I found that some
of my Java script did not want to work. After eventually examining the HTML
view of the new and old form for differences, I noticed the DOCTYPE lines
pretty close to the top of the forms in HTML view differ. I removed the line
in the new form and my Java script worked. Today I noticed that a SPAN on a
new form with the width property set to 100% displayed about 1/4 over the
page, so I thought let me give the DOCTYPE line a shot, I removed it and the
SPAN displays perfectly. So, I am not sure if the DOCTYPE line generated by
VS2005 is evil or a new standard, but it surely causes problems.
 
J

Joerg Jooss

Chris said:
I am porting an existing 2003 project to 2005. Yesterday I found that
some of my Java script did not want to work. After eventually
examining the HTML view of the new and old form for differences, I
noticed the DOCTYPE lines pretty close to the top of the forms in
HTML view differ. I removed the line in the new form and my Java
script worked. Today I noticed that a SPAN on a new form with the
width property set to 100% displayed about 1/4 over the page, so I
thought let me give the DOCTYPE line a shot, I removed it and the
SPAN displays perfectly. So, I am not sure if the DOCTYPE line
generated by VS2005 is evil or a new standard, but it surely causes
problems.

What you experience is called "quirks" mode. See
http://www.quirksmode.org/css/quirksmode.html for more details.

Here's how IE 6 decides between quirks and standards compliant mode:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnie60/
html/cssenhancements.asp

Unfortunately, Visual Studio .NET 2002 and 2003 both use a default
DOCTYPE in ASP.NET that *enables* quirks mode.
[Hony soit qui mal y pense ;-)]

What does all that mean for your HTML? If it requires quirks mode, it's
most likely broken...

Cheers,
 
K

Kevin Spencer

The following JavaScript will allow the "width" style for spans to work in
all browsers, regardless of DOCTYPE:

<script type="text/javascript" >
var sps = document.getElementsByTagName("span");
for (var index = 0; index < sps.length; index++)
{
var sp = sps[index];
if (sp.className == "label")
{
var s = sp.style.width.substring(0, sp.style.width.indexOf("px"));
var i = (s - sp.offsetWidth) / 2;
if (sp.style.textAlign == "center")
{
sp.style.paddingLeft = i;
sp.style.paddingRight = i;
}
else if (sp.style.textAlign == "right")
sp.style.paddingLeft = i * 2;
else
sp.style.paddingRight = i * 2;
}
}
</script>

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

Joerg Jooss said:
Chris said:
I am porting an existing 2003 project to 2005. Yesterday I found that
some of my Java script did not want to work. After eventually
examining the HTML view of the new and old form for differences, I
noticed the DOCTYPE lines pretty close to the top of the forms in
HTML view differ. I removed the line in the new form and my Java
script worked. Today I noticed that a SPAN on a new form with the
width property set to 100% displayed about 1/4 over the page, so I
thought let me give the DOCTYPE line a shot, I removed it and the
SPAN displays perfectly. So, I am not sure if the DOCTYPE line
generated by VS2005 is evil or a new standard, but it surely causes
problems.

What you experience is called "quirks" mode. See
http://www.quirksmode.org/css/quirksmode.html for more details.

Here's how IE 6 decides between quirks and standards compliant mode:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnie60/
html/cssenhancements.asp

Unfortunately, Visual Studio .NET 2002 and 2003 both use a default
DOCTYPE in ASP.NET that *enables* quirks mode.
[Hony soit qui mal y pense ;-)]

What does all that mean for your HTML? If it requires quirks mode, it's
most likely broken...

Cheers,
 
C

Chris Botha

Hi Kevin, I should have mentioned that the span width is set on the style of
the span, thus:
<span style="WIDTH: 100%; .....>

So what I am saying is that Java script as well as normal HTML breaks with
the DOCTYPE settings used by VS2005.
The Java script that broke was (1) I've set a handler for the
document.onscroll and the event did not fire any more, and (2) on another
form I had something like theDiv.scrollIntoView().

Thanks in any case.


Kevin Spencer said:
The following JavaScript will allow the "width" style for spans to work in
all browsers, regardless of DOCTYPE:

<script type="text/javascript" >
var sps = document.getElementsByTagName("span");
for (var index = 0; index < sps.length; index++)
{
var sp = sps[index];
if (sp.className == "label")
{
var s = sp.style.width.substring(0, sp.style.width.indexOf("px"));
var i = (s - sp.offsetWidth) / 2;
if (sp.style.textAlign == "center")
{
sp.style.paddingLeft = i;
sp.style.paddingRight = i;
}
else if (sp.style.textAlign == "right")
sp.style.paddingLeft = i * 2;
else
sp.style.paddingRight = i * 2;
}
}
</script>

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

Joerg Jooss said:
Chris said:
I am porting an existing 2003 project to 2005. Yesterday I found that
some of my Java script did not want to work. After eventually
examining the HTML view of the new and old form for differences, I
noticed the DOCTYPE lines pretty close to the top of the forms in
HTML view differ. I removed the line in the new form and my Java
script worked. Today I noticed that a SPAN on a new form with the
width property set to 100% displayed about 1/4 over the page, so I
thought let me give the DOCTYPE line a shot, I removed it and the
SPAN displays perfectly. So, I am not sure if the DOCTYPE line
generated by VS2005 is evil or a new standard, but it surely causes
problems.

What you experience is called "quirks" mode. See
http://www.quirksmode.org/css/quirksmode.html for more details.

Here's how IE 6 decides between quirks and standards compliant mode:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnie60/
html/cssenhancements.asp

Unfortunately, Visual Studio .NET 2002 and 2003 both use a default
DOCTYPE in ASP.NET that *enables* quirks mode.
[Hony soit qui mal y pense ;-)]

What does all that mean for your HTML? If it requires quirks mode, it's
most likely broken...

Cheers,
 
C

Chris Botha

Hi Joerg, thanks for the links. That such a subtle thing can cause so many
problems (I debugged for quite a while before I stumbled upon it). When I
see a funny in a page now, first thing I do is to remove the DOCTYPE.
[Shame to him who thinks evil of it :)]

Thanks.


Joerg Jooss said:
Chris said:
I am porting an existing 2003 project to 2005. Yesterday I found that
some of my Java script did not want to work. After eventually
examining the HTML view of the new and old form for differences, I
noticed the DOCTYPE lines pretty close to the top of the forms in
HTML view differ. I removed the line in the new form and my Java
script worked. Today I noticed that a SPAN on a new form with the
width property set to 100% displayed about 1/4 over the page, so I
thought let me give the DOCTYPE line a shot, I removed it and the
SPAN displays perfectly. So, I am not sure if the DOCTYPE line
generated by VS2005 is evil or a new standard, but it surely causes
problems.

What you experience is called "quirks" mode. See
http://www.quirksmode.org/css/quirksmode.html for more details.

Here's how IE 6 decides between quirks and standards compliant mode:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnie60/
html/cssenhancements.asp

Unfortunately, Visual Studio .NET 2002 and 2003 both use a default
DOCTYPE in ASP.NET that *enables* quirks mode.
[Hony soit qui mal y pense ;-)]

What does all that mean for your HTML? If it requires quirks mode, it's
most likely broken...

Cheers,
 
J

Joerg Jooss

clintonG said:
<snip />

So what's the general consensus when building VS2005 2.0
applications? Any Target Schema suggestions? The Master is currently
using this...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html
xmlns="http://www.w3.org/1999/xhtml" >

<%= Clinton Gallagher

It really depends on your both clients (browsers) and clients (the guys
giving you money).

Personally, I'd stay from quirks mode whenever possible, especially if
supporting multiple browser types is a requirement. One quirk that
works fine in one browser may cause disaster in another browser.

If accessibility is a requirement, you most likely have to render
standards compliant HTML -- many screenreaders don't work too well with
quirks mode HTML, and laws or regulations regarding accessibility may
simply prescribe that only standards compliant HTML is to be used for
certain types of web sites (government agencies etc.).

Cheers,
 

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

No members online now.

Forum statistics

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

Latest Threads

Top