Can't work out how to get valid HMTL pages from ASP.NET

Mark R

Diamond Member
Oct 9, 1999
8,513
16
81
A requirement for a current project is that the pages be strict HTML 4.01 - I simply can't get ASP.NET to produce said HTML.

I've already solved the problem of Browsers other than IE not being recognised, but this seems to be a more tricky problem.

The specific problem is the hidden viewstate field, which I have no control of programatically, yet is not valid HTML.

Here's a snippet of source (note that I've had to hack it a bit just to be able to post it - I've added "-" to each HTML tag).

The specific error found by the W3c html validator is:

"document type does not allow element "INPUT" here."
Which means that the hidden {input} tag must be enclosed in a div or similar tag.

Any ideas how to fix this?
 

Mark R

Diamond Member
Oct 9, 1999
8,513
16
81
The '-'s are there because you cannot post correctly formed tags to this forum.

The tags are correctly formed in the actual code.
 

Mark R

Diamond Member
Oct 9, 1999
8,513
16
81
Have you tried putting a div tag around the outside of the form?

Yes. It makes no difference.

In order for it to be valid HTML, the actual < input> tag must be enclosed in a div which is itself nested within the < form> tag.

ASP.NET places the < input> tag directly after the < form> tag, so you cannot simply place HTML code in the .aspx file. It just appears after the < input> tag.
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
Originally posted by: Mark R
Have you tried putting a div tag around the outside of the form?

Yes. It makes no difference.

In order for it to be valid HTML, the actual < input> tag must be enclosed in a div which is itself nested within the < form> tag.

ASP.NET places the < input> tag directly after the < form> tag, so you cannot simply place HTML code in the .aspx file. It just appears after the < input> tag.

I take it using the new version of asp.net is not an option? If not, try this article's technique... http://www.charon.co.uk/content.aspx?CategoryID=28&ArticleID=53
 

Mark R

Diamond Member
Oct 9, 1999
8,513
16
81
Thanks so much! It's now working.
Unfortunately, I can't change to .net v2 - so I'm stuck with v1.1 - for work anyway.

However, that fix is certainly an ugly workaround - and I've no idea what the performance would be like on a busy site. But hopefully, as this is likely to be a relatively light load site this won't be a problem.