Tech Off Thread

22 posts

ASP.net 2.0 not XHTML 1.1 compliant?

Back to Forum: Tech Off
  • Xenon101

    Well it would seem that ASP.net 2.0 isn't compliant with XHTML 1.1...well that isn't the end of the world, it complies fine with XHTML 1.0 Transitional, however XHTML 1.1 seems stricter and the "<form runat=server>" part actually outputs uncompliant code.

    Now in VWD Express 2005 when writing an ASP.net page it automatically declares the DOCTYPE as being XHTML 1.1, is there any way I can change this to be XHTML 1.0 Transitional (for every new page i create) or are M$ planning to make ASP.net 2.0 XHTML 1.1 compliant eventually? Smiley

    Edit: the incorrect code is the NAME tag in the FORM element...this only appears to show up on the XHTML validator however it doesn't appear when viewing page source in IE Perplexed very confusing!

  • HyBreeD

    There are actually a few ways that you can override this, but look at the Page.ClientTarget property. It should serve as a good starting point. Smiley

  • Maurits

    Xenon101 wrote:

    Edit: the incorrect code is the NAME tag in the FORM element...this only appears to show up on the XHTML validator however it doesn't appear when viewing page source in IE very confusing!


    Presumably there's some user-agent sniffing going on.  Try using a different browser, or manipulating the HTTP request via Fiddler or some such tool.

  • sbc

    HyBreeD wrote:

    There are actually a few ways that you can override this, but look at the Page.ClientTarget property. It should serve as a good starting point. Smiley


    You shouldn't need to do that. If something is advertised as being compliant with a standard it should be 100% compliant. The developer should not have to do extra work.

    It may seem minor, but for some it is important. Don't advertise a feature if that feature does not do what it is meant to do.

  • d-snp

    The normally outputted code is valid xhtml 1.1 but certain functions are disabled for browsers other than IE through settings in your web.config file. Please don't say this is minor, cause it isn't (alternative browsers are said to be used by 10% of the internet population and rising). You can either change the settings in your web.config file, or add clientTarget="ie5" to your page line in your aspx file if you're sure the code you've written will work on every browser. This will ensure that the correct code is being output for all your clients.

    You may argue about why microsoft decided to set these web.config settings as default (3 times because asp.net 1.0 and 1.1 also suffer from this) but I doubt that is within the scope of this topic

  • W3bbo

    d-snp wrote:
    alternative browsers are said to be used by 10% of the internet population and rising


    I wouldn't call non-IE browsers "alternative", that's implying "lesser" in certain dielects.

    Rather, how about "competing" (or even "better" Wink ) browsers?

    And your figure of 10% is wrong, IE is now down to around 60% on some sites, (including my own), but generally speaking IE is used between 75 and 85% of the time.

  • Tensor

    IE still over 90% on our none-techy ecommerce site!

  • Maurits

    There's several things to consider when looking at browser percentage for your site.

    Site audience plays a large role.  Businesses tend to be IE-only.  Home users are strongly IE, with a mix of Firefox and some Safari.  Students are more diverse.  Web developers are probably the most diverse.

    Also, site design plays a role.  If your site breaks in Firefox, many Firefox users will switch to IE or "switch to IE" (via User Agent Switcher.)

    I'd be interested to see the user-agent statistics for Channel 9.

  • Raindog

    I recently set myself the task of making the ecommerce site for the company I work for XHTML 1.1 compliant. I discovered that once you set the compatibility mode in the web.config to 1.0 strict, it was only a short hop up to 1.1, until I hit a snag.

    When using web forms, .net automatically inserts the name of the form in the form tag which messes up 1.1. Fortunately I discovered this article and was able to remove the offending name attribute aspnetresources.com/.../HttpFilters.aspx

    I'm not sure how many asp.net 2.0 XHTML 1.1 compliant sites there will be out there, but I doubt whether it will be many http://www.click2qnet.com

    I tend to design for Firefox then tweak the css and other functionality for IE, though with the advent of IE7 there is much less of this to do, at last!

  • Sven Groot

    Raindog wrote:
    When using web forms, .net automatically inserts the name of the form in the form tag which messes up 1.1. Fortunately I discovered this article and was able to remove the offending name attribute aspnetresources.com/.../HttpFilters.aspx

    Why did you revive an ancient thread for this?

    Anyway, the name attribute is added to <form> elements only when ASP.NET 2.0 is in downlevel rendering mode, i.e. for browsers it does not know. Unfortunatley, it doesn't recognize the W3C validator, so that will get invalid XHTML. But IE6+ and Firefox will get correct versions.

  • Raindog

    Perhaps so, but when you link to the W3C validation service it falls into the category of a "not recognised" browser when it connects to your page as you mentioned.

    By using a simple bit of code in the page preInit you can remove it from the output and it caters for all browsers

    Besides this may be an 'ancient' thread as you call it, by web standards it may be, but that's the nature of the beast, constant turmoil. Bit of chaos never hurt anybody:)

  • Sven Groot

    Raindog wrote:
    Perhaps so, but when you link to the W3C validation service it falls into the category of a "not recognised" browser when it connects to your page, so it may render nicely in firefox but as soon as someone validates a page using a webform, it falls down because .net renders the name attribute. By removing it in the page pre_init, you cater for all browsers and it validates.

    You can create a .browser file that causes ASP.NET to recognize the validator. Or you can change the default so it doesn't use downlevel rendering for unrecognized browsers.

  • Raindog

    I could have done that, but I wanted to see if I could do it my way, I saw it as a challenge to beat Microsith and I managed it so I was happy! Smiley

    Besides, it may be that you don't have access to the defaults, it may not be your .net installation, or if your migrating servers, you may forget to change the defaults. I thought this way was a more integrated method, its built in as part of the site itself.

  • Sven Groot

    Raindog wrote:
    Besides, it may be that you don't have access to the defaults, it may not be your .net installation, or if your migrating servers, you may forget to change the defaults. I thought this way was a more integrated method, its built in as part of the site itself.

    None of that matters. All you need to do is put a relevant .browser file in the App_Browsers folder of your site. You can even modify the defaults that way. You can modify the behaviour for any pre-existing browser that way. And you won't need to change any system files, and you won't affect any other sites on the same server.

    Plus you'd be doing it the way it was designed to be done.

  • Raindog

    Which will probably change at some point in the future anyway so I'll do it my way and know that it works, I'm not truly convinced by .browser files anyway, they seem a somewhat messy solution to a problem that can be solved by a few lines of code which handles all browsers. Far more efficient in my opinion.

    I use code to move the viewstate on web forms and I put the code in that method, this way I have all that form handling functionality in one place instead of having to bother with other elements of the site.

  • Sven Groot

    Well, nobody is forcing you to use .browser files. But these are a documented method, so they are far more likely to remain working than your hack.

    Also, does your code deal with the many other changes in rendering that ASP.NET has when it goes into down-level mode? Especially the more complex controls have vast differences (for some reason, ASP.NET likes to replace <div>s with <table>s in many cases).

    With the .browser file approach, you can catch everything for all browsers with just a few lines of XML. I do this myself, it works great.

  • JChung2006

    I would really hate to be the guy who has to maintain Raindog's code after he is gone...

  • phreaks

    Why doesn't ASP.NET output Lynx compatible HTML?

    WTH, @#$&! Micro$oft, trying to keep the Lynx users down...

    :O

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.