HTML Validation Checking in VS 2005 (and how to optionally turn it off if you want)

I posted earlier about some of the cool new HTML source editor features in VS 2005 and Visual Web Developer.  One of the big new things is much richer html source validation.  Specifically you can now validate against different HTML schemas and standards (XHTML Transitional/Strict, HTML 4.01, and various browser types).

 

In addition to validating against the HTML element schemas, VS 2005 and Visual Web Developer also by default now validates CSS inline styles, casing and termination of HTML tags (for example: to force lower case and close tags), and performs link and image reference validation.

 

For example, if you have an html hyperlink anchor in your page that points to a local file that doesn’t exist, or an image element that points to a local image that doesn’t exist, you will now see red squiggles in your source editor:

 

 

And if the html document is open you will also see relevant errors in your error list (if you click on any of the errors in the error list you will automatically jump to the issue in the source):

 

 

 

Important: HTML validation errors do not block a web project from compiling or running.  As such they can optionally be ignored if you do not want to deal with them (although our recommendation would obviously be to review them closely and fix them). 

 

The reason we are now surfacing HTML validation issues in the error list by default is that we are trying to promote more standards-based html with VS 2005 and ASP.NET 2.0, as well as to catch potential rendering and browser functionality errors earlier in the development process (so that you don’t have to run and carefully analyze every page in your app looking for these types of issues).  

 

If you’d rather not have these types of HTML validation errors show up in your error-list, you can disable this functionality by selecting the Tools->Options menu item in VS or Visual Web Developer.  Select the TextEditor->Html->Validation tree option in the left-hand side of the options window, and uncheck the “Show Errors” checkbox:

 

 

Note that another possible reason to turn this setting off might be if you are seeing performance problems when editing very large documents on your system (I personally find my laptop 1.4Ghz machine is able to edit 4000 line html files just fine with full validation on – but your mileage may vary depending on your exact hardware configuration).  The HTML validation occurs in the background on idle, so shouldn't get in the way -- but if you are tight on cycles turning it off can probably spare you a few timeslices on your CPU.

 

Hope this helps,

 

Scott

33 Comments

  • Scott,



    I just want you to know that the community really appreciates that you are probably working 80 hours per week (including your weekends) to address our concerns and questions as we are migrating to 2005.



    This support is much appreciated by us all.



    Thanks,



    David Taylor

  • Hi Scott,



    You won't get any argument from me that this is a cool feature <g> - having the list there is 'educational' for many things and it's been helpful in having me clean up a lot of gunk especially in some fairly old applications.



    I think my beef with it is just the representation. I argued this point during the beta with a few people at Microsoft <g> and lost the fight. I think if there were some way to get these errors easily filtered out or off onto another tab this feature would be just fine. I think it's very interfering in the Errors list which should be reserved for 'break the build errors'.



    One question you didn't address: How will you deal with updated standards as they change and will end up showing errors for things that essentially aren't broken?



    Oh and BTW, the color issue in the screen shot *is* with IE 6.0 setting not with XHTML.



    Thanks for the feedback!



    +++ Rick ---

  • Hello Scott,



    Do you know if there is a similar option to turn off parsing of QuickBasic .bas files. These have a similar problem of generating errors if a .bas is opened in the IDE when building other components.



    Simeon

  • Hi Rick,



    I like the tab button filter idea on the errorlist -- I'm going to push to try and add this to the next release. In the meantime, one cheesy way to toggle things would be to just write a macro that you can associate with a keybinding to turn the error off and on.



    The nice thing with all of the schemas is that they are just XML files, and you (or Microsoft) can author new ones and add them to the system anytime. This makes it pretty easy to rev, and we will keep them up-to-date as new standards emerge. Developers in VS can then just pick whichever one they want to validate against from the drop-down.



    On the color issue front, are you 100% sure it is with IE6? I just tried a test again where I was using a color in an inline CSS style property -- and it causes problems with XHTML Transitional (the exact error messages you were listing), but disappeared when I selected IE 6.0.



    Note that the validation occurs on background idle in the IDE -- so if you previously had XHTML on it might just take a few seconds for the validation to re-apply with the new filter (especially with large files). Maybe you were seeing it complain because of that?



    Thanks,



    Scott

  • One thing that does bug me is that when adding an attribute to an html element, the IDE doesn't automatically insert two quotes (") when you hit equals (=) as it does when coding XML.



    Is there a way to get this to happen?

  • Ignore my last post, I just found the solution. It's a formatting option in VS that isn't checked by default. Trust me to find it 30 seconds after posting here. :)

  • Cheers Scott,



    It didn't understand the QuickBasic, it assumes it was VBx. So some stuff was parsed correctly, but other bits caused errors. Cheers for digging around the menu's all the same.



    Simeon.

  • One thing that would be neat is some sort of 'click Fix' for the common html errors.



    By common in my case this means:



    - No closing slash on br tags

    - No closing slash on img tags

    - tags in uppercase

    - img tags without alt



    Mayby this is there already, mayby someone's done a macro for this type of quick cleanup???



    jason.

  • Hi Jason,



    That is definitely a good suggestion (kind of like how Word does auto-correct fixups)!



    Thanks,



    Scott

  • I cannot find this anywhere, but Visual Web Developer is always trying to finish my statements before I want it to. Especially bad is the <&pct; tag which is closed automatically causing me to pull out hair. Also, If automatically adds "then" and "end if". I do not want this to happen!

    How can I disable this "feature"

  • Hi Scott,

    If you select the Tools->Options menu option, you can modify the VS/Visual Web Developer settings to not auto-complete for you.

    To disable auto-closing of tag elements, unselect the "Auto Insert Close Tag" checkbox under the HTML->Validation option.

    Hope this helps,

    Scott

  • Hi Brian,

    Here is a post I did that talks about how to add new validation schemas into your drop-downlist: http://weblogs.asp.net/scottgu/archive/2006/02/02/437228.aspx

    Good luck with it!

    Scott

  • Hi Scott,

    I'm having a problem where VS2005 keeps re-checking the Show Errors checkbox.

    As much as I love the validation I really need it off to allow a workaround I am using...I have to put a dummy style tag after an ATLAS UpdatePanel so that my Infragistics control doesn't lose its style after an async postback.

    The style tag isn't valid in a div so I am prevented from switching to design view.

    So anyway, every time I uncheck "Show Errors" it seems to re-enable as soon as I try to switch to design view.

    Ideally, I'd like to avoid the style tag workaround - but in the meantime, is there anyway I can force the "Show errors" checkbox to stay unchecked?

    Many thanks

    Stuart

  • Hi Stuart,

    Unfortunately if you do a view-switch into design-view and there is an error that blocks the designer from switching successfully, the show errors checkbox automatically gets re-added. :-(

    This will be fixed, though, with the SP1 release that is coming out. Until then you'll probably need to keep turning it off manually.

    Sorry!

    Scott

  • I'm being forced to migrate a site from ASP to ColdFusion, and VWD 2005 Express Ed. is making it hard to rewrite code in CFML.

    For example if have this line of code:



    and I copy and paste it in the IDE, it's automatically edited to:



    this is making me quite mental i must say :)

    How do I disable this auto-editing?

  • Its pathatic.

    VS 2005 does not allow to deactivate Validation optionn of HTML that block the designer to complete their job.

  • Hi .NET Developer,

    With VS 2005 RTM, when you try to perform a view-switch and there is a parse error, validation gets turned back on.

    With VS 2005 SP1 Beta and beyond this behavior doesn't happen.

    Hope this helps,

    Scott

  • How can we get F1 or Help to be context sensitive for these validation errors? Hitting F1 on the error in the task window provides no help.

  • Hi Mikee,

    If you pull up the Error List (View->Error List menu item) it will detail any validation error you have.

    Hope this helps,

    Scott

  • Hi Scott
    I would not mine the errors if I could find out how to correct them. I have CSS errors dealing with the Scrollbar settings and I cannot find how to correct them.

  • Hi Scott

    Is there a way to cause intellisense to add the asp tag attributes in lower case so that the XHTML validation doesn't complain as follows: Validation (XHTML 1.0 Transitional): This name contains uppercase characters, which is not allowed

    Thanks

  • Hi Gareth,

    If you right click in the text editor you can select "formatting options". This allows you to control the default casing and formatting of server controls when they get added to a page.

    Hope this helps,

    Scott

  • How can i turn it on for all pages? i like to brows all the pages error to decide to fix then or not. the current validation is working only in the opened pages. can i browse all the pages validation errors without opeing every page.

  • Why are these items missing in the "Target:" DropDownList in the "Options" dialog box at the top of this page?

    * HTML 4.01 (which one is it?)

    * HTML 4.01 Transitional (missing)
    * HTML 4.01 Strict (missing)
    * HTML 4.01 Frameset (missing)

    * XHTML 1.0 Transitional (present)
    * XHTML 1.0 Strict (missing)
    * XHTML 1.0 Frameset (present)

    etc.?

  • I have the check box UNCHECKED and I still get the validation.

    Dave

  • I might have gotten past it! If you set your validation to IE6 and then uncheck the Show Errors check box, you might get past it. Mileage may vary.

  • funny thing is, there are asp.net controls that don't render as valid XHTML 1.0. for example, look at the mess a RequiredFieldValidator will render, last i checked the "controltovalidate" attribute was not sanctioned by the W3C. at least the attribute is properly cased.

  • Hi Cmv,

    ControlToValidate is a server side attribute, I don't believe it is rendered on the client.

    Thanks,

    Scott

  • Scott...maybe i'm doing something wrong but i can't for the life of me figure out why the RequiredFieldValidator is rendering like this:
    *
    that is what appears when i view source. this is in a project that was recently converted from 1.1 to 2.0.

  • Hi, we're converting a large VS 2003 project. Ideally, we'd like to move up to "XHTML 1.0 Transitional" as defaulted by VS 2005.

    To do so, however, means a huge amount of manual work. Is there a more automated way of migrating pages over... maybe a few tools that auto-fix the obvious issues (like upper/lowercase changes, etc.).

    Thanks !

  • Hi Noy,

    Unfortunately I don't know of any totally automated way to switch these pages over I'm afraid. :-(

    Sorry!

    Scott

  • Hi CMV,

    Can you check your web.config file to see whether you have an attribute set? This is inserted when you use an upgrade wizard, and turns off XHTML compliance. That might be what you are running into.

    Thanks,

    Scott

  • that took care of the issue, thanks!

Comments have been disabled for this content.