I am wondering if there is a way to detect from the server-side which DOCTYPE the page is specified as. I have some HTML and CSS in a custom WebControl that renders differently depending on which DOCTYPE the page is. Is there a Page
property or a Response
property I could check?
views:
50answers:
2
A:
Why don't you have an enum or a boolean on your control that the consuming pages can set (it's not like the doctype should be changing from page to page)?
TheCloudlessSky
2010-07-14 15:26:31
i'm taking our old TABLE-based container control and changing it to a less-markup (and better) DIV-based container, ideally making it function and display same as it did before the change. But I can't guarantee all of the pages in all our apps have DOCTYPE set to Transitional
SAGExSDX
2010-07-14 16:00:51
Why don't you do as I suggested then? Have each page individually set a variable?
TheCloudlessSky
2010-07-14 16:04:58
We have a lot of apps with a lot of pages. The ideal solution would be to have a custom WebControl that can adapt itself instead of having developers be responsibly for managing a variable.
SAGExSDX
2010-07-14 16:09:32
Ok, then why don't you create two seperate controls? The *ideal* solution would be to take the time to copy-paste the proper doctype when you add the control obviously...
TheCloudlessSky
2010-07-14 17:07:22
The thing is, this control is already in use. but when people move forward to a newer WebControls DLL, the markup for the control will be different.
SAGExSDX
2010-07-15 13:13:15
A:
Thing is, DOCTYPE is a client side declaration and it doesn't take part the control structure of ASP.NET pages (because it exists outside the html
element of the page). I concur with @TheCloudlessSky, pass the setting to the control, as the only way I can see you detecting DOCTYPE is by opening up the file itself and reading the first line, this is also pretty useless for compiled web applications too.
Why will the DOCTYPE be changing from page to page?
Matthew Abbott
2010-07-14 15:37:05
Ideally, all pages in all of our apps would have the same Visual Studio DOCTYPE, but I don't want to just assume that. I can also see other developers possibly changing it. Why? I don't know. Devs do funny things sometimes. ;)
SAGExSDX
2010-07-14 16:02:50
To be honest, you're probably best just making your user control produce consistent semantic markup, based on XHTML. It's not going to harm any renders which use say, HTML4, XHTML1.0, XHTML1.1 or HTML5.
Matthew Abbott
2010-07-14 16:11:16