The World’s Leading Microsoft .NET Magazine
   
 
timstall

Donate Today!

Search Box

 

Calendar

««Mar 2010»»
SMTWTFS
  12
3
456
7
8
9
10
111213
14151617181920
21222324252627
28293031

My RSS Feeds








Mailing List

Most Popular Tags

                                                           

Visual Studio Design Mode Changing your Html

posted Thursday, 14 July 2005

Occasionally Visual Studio (2003) changes the Html when you go to design mode. While it reformats it, it may also add certain closing tags. This can be counter-productive if you're doing certain techniques where you want the Html to be the way you initially made it. I've heard rumors that 2005 guarantees that your Html won't get altered.

I see this Html changing in two categories:

  1. Ways you can solve it by adding extra html, such as multiple nested tables
  2. Ways that Visual Studio is just wrong

The problem with the first is that any extra html you add must be transported over the wire and rendered on the client, so it slows performance. The only helpful technique I know to avoid needing that extra overhead is to make Visual Studio open in Html view by default.  Goto: Tools > Options > Html Designer > General, and set the options to open in Html instead of Design view. Ideally your UI is refactored enough (with user controls, base pages, custom controls, possibly #includes, etc...) that the Html can be managed in Html view. I can then save my page, "peek" in design view to check the overall layout, disregarding any potential changes from Visual Studio.

In the second category, one (seemingly) blatant bug I came across in Visual Studio was when I had a custom control with custom attributes, and the attribute didn't have a value (kind of like "nowrap" - it only needs the attribute, not any associated value). Something like:

<myControls:myControl1 runat="server" id="c1" attribute1 attribute2="abc" attribute3="xyz">...

kept getting maligned to something like below when I went to design view. The attribute values got disjointed from the attributes:

<myControls:myControl1 runat="server" id="c1" attribute1attribute2 attribute3="xyz"="abc">...

However if I put the value-less attribute at the end, then I could toggle back and forth between Html and Design view:

<myControls:myControl1 runat="server" id="c1" attribute2="abc" attribute3="xyz" attribute1>...

I'm not sure what causes this - it could be something with the custom control, value-less attribute, affect from other attributes, or something else, but it solved that particular problem.

links: digg this    technorati    




1. Wayne Johnson left...
Monday, 17 October 2005 9:40 am

I have trouble with VS changing my html.

i have top.ascx and bottom.ascx

and have <div> is top.ascx and </div> in bottom.ascx trouble is top.ascx switching from design to html tries to be clever and close the tag which is wrong.

Anyone help?


2. Tim Stall left...
Wednesday, 19 October 2005 5:32 pm

Hey Wayne,

  • I've heard that VS 2005 no longer breaks our Html, but in the meantime my best guess is that you can (1) either restruture the userControls such that they don't break up the div tag, or (2) set you default view to be Html and never show those UC in design mode.


3. Jeff Davis left...
Wednesday, 21 December 2005 11:11 am :: http://www.fairfaxcounty.gov/

I have also experienced this stripping of html when switching between design and HTML views. I'll try the setting to always open in HTML view and if using Design, check whether the following two offences have been perpetrated: 1. That Visual Studio complains that the stylesheet link which includes a dynamic path needs a closing end link tag, but will often strip it off(!), e.g. <link type="text/css" rel="stylesheet" runat="server" id="lnkDepartmentStyleSheet" href="<%#departmentStyleSheetPath%>" > 2. That it will strip off the "runat=server" from another control on the page, e.g. <title runat="server" id="HtmlTitleTag"></title> I use this to dynamically set the title at run time in the VB code.


4. zdux0012 left...
Friday, 28 April 2006 6:58 pm

Yes this "feature" of Visual Studios should bring Microsoft shame. It is a terrible annoyance to never know where your html code will be from day to day.

Rather than get the new 2005 version that fixes this bug we should demand that MS fixes their bugs.