Saturday, March 24, 2012

The element html occurs too few times.

I am using Beta 2 and have a problem with aspx files in that it is refusing to compile unless I have a top level HTML element. The problem with this is that I do not want to define the top level html in the aspx page, I want to define it in a usercontrol and then load that dynamically at runtime just as I can in ASP.NET 1.1. Surely there are other reasons you would want to have an aspx page without an <html> tag in it, I can think of several, why is there this limitation as it severly limits flexibility.
It says "The element 'html' occurs too few times."
Is there anyway to turn off this error to get it to compile?
Richard
"Surely there are other reasons you would want to have an aspx page without an <html> tag in it"
Like when? an aspx page is goign to spit out an HTML document, so the <html> tag makes perfect sense
Sounds like you have your programming all backwards, the aspx page should have the shell and the user controls should have the dynamic content, not the other way around
Like for example when you are trying to output WAP content for one, or plain text for another.
This is because I need to be able to easily substitute the head sections primarily dynamically, this enables multiple sites to run on the same codebase looking for Host headers to load the appropriate templates, it also allows easy support for text only versions of sites, just by dynamically loading text only versions of the user controls, this is for a database driven website content managed system.
Ive looked into master pages but they dont seem to really allow enough flexibility to do what I need to do as they require the definition of the whole document in them, but maybe ill have to work out some way to fudge it with those.
Im not sure what you are refering to about doing it backwards, the aspx page is the shell that loads up the user controls, and the user controls are what contain the dynamic content.
Hello.
Are you also removing the <head> section from the page? I've noticed in the past that if you remove the <html> tag but leave the <head runat="server"> you'll get that errror when you build the project in VS.
one more thing: you can use "filters" to apply different master pages to different browsers. for instance:

<%@.PageLanguage="C#"ie:MasterPageFile="~/Cap14/IE.master"MasterPageFile="~/Cap14/Mozilla.master"%>
applies a master page to IE and another to the other browsers. Check your browsers files to see the IDs of the browsers... oh, and you can alsouse adapters to render your pages/controls according to your needs in different browsers...


I don't think missing <html> element is an error. It is HTML markup validation message and is supposed to be a warning. Does it really break compilation or the page still runs? You can deal with the message in a few ways. First, you can disable validation in Tools | Options | Text Editor | HTML | Validation. Second, you can edit validation schema in Program Files\...\Common7\Packages\schemas\html (IE6_0.xsd, for example) and delete minOccurs="1" maxOccurs="1" from the <xsd:element name="html" >. Third, instead of using ASPX page, you can define your own file type, add it to the web.config and implement a handler for the type that will generate the response programmatically.

Giving it a fuller test it doesnt seem to break compilation on its own, I was getting other compilation errors too which were actually stopping it, but it does get reported as an error rather than a warning along with the other errors leading you to believe it is stopping compilation and needs to be fixed before you can compile.


I say just ignore it. If you are making an XML page, you can't have the <html> tag, for instance. So, just ignore it. That's what I do.

0 comments:

Post a Comment