|
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:
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:
|
kept getting maligned to something like below when I went to design view. The attribute values got disjointed from the attributes:
|
However if I put the value-less attribute at the end, then I could toggle back and forth between Html and Design view:
|
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.
I have trouble with VS changing my html.
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.
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.
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.