Kevin Dente's Blog

The Blip in the Noise
Absolute positioning in VS2005 HTML designer

In Visual Studio .NET 2003, ASPX pages included a property called pageLayout, which defaulted to “GridLayout” – essentially, CSS absolute positioning for all form elements. Although this is a horrible idea in a production application (I assume MS did it to make it easier to demo rapid application building), it does turn out to have a handy use – it makes it easy to quickly sketch out web forms for UI design or prototyping.

Visual Studio 2005 did away with the pageLayout property on web forms, but it did include a similar capability in the HTML Designer. The Tools/Options/HTML Designer settings page includes positioning options that allow you to create a very similar (though exactly the same) experience to pageLayout=”GridLayout”. To enable it, check the “Change positioning to the following for controls added using the Toolbox, paste, or drag and drop” option, and select “Absolutely positioned” in the combo box. This recreates most of the GridLayout experience, with one exception – new controls that are dropped onto the design surface always show up initially in the upper-left hand corner. They can then be dragged to any position on the form. In VS2003, controls appear exactly where they are dropped.

The option described above is a global setting, which can make it inconvenient to use. Fortunately, it’s not too hard to cruft up a macro that toggles the state of the CSS position option:

Sub ToggleCssPositioning()
   Dim autoPositioningProperty As [Property] = DTE.Properties("TextEditor", "HTML Specific").Item("AutoPositioning")
   Dim autoPositioningModeProperty As [Property] = DTE.Properties("TextEditor", "HTML Specific").Item("AutoPositionMode")

   If (autoPositioningProperty.Value = 0) Then
      |
autoPositioningProperty.Value = 1
      autoPositioningModeProperty.Value = 0
   ElseIf (autoPositioningProperty.Value = 1) Then
     
autoPositioningProperty.Value = 0
   End If
End Sub

Hook the macro up to a toolbar button, and you can easily switch between the two modes. Unfortunately, it doesn’t seem that VS2005 macros that are assigned to toolbar buttons can be represented as toggle buttons, so the UI doesn’t give you a clear indication of what mode you’re in. Maybe some day I’ll think about wrapping this up into an addin.

 

 

Published Tuesday, August 01, 2006 9:51 PM by kevindente

Filed under: ,

Comments

# re: Absolute positioning in VS2005 HTML designer@ Wednesday, November 08, 2006 12:13 PM

I tried it with a user controls with still unable to position exactly where I wanted.  Is there an alternative way?

Thanks

Steve

# re: Absolute positioning in VS2005 HTML designer@ Wednesday, November 08, 2006 3:58 PM

You need to enable absolute positioning *before* you drop the control onto the form. If it's already there, it won't enable abs. pos. for it. Could that be the problem for you?

kevindente

# re: Absolute positioning in VS2005 HTML designer@ Wednesday, February 07, 2007 11:27 PM

Very helpful!  thanks for posting this.

Rick

# re: Absolute positioning in VS2005 HTML designer@ Tuesday, June 19, 2007 6:41 AM

I cold not able to get scroll bar on the side of the web designer form in asp.net.could u help me.please?

sunil

# re: Absolute positioning in VS2005 HTML designer@ Monday, July 16, 2007 2:21 PM

ha ha ha i can move freely now thank u very much

rahul reddy

# re: Absolute positioning in VS2005 HTML designer@ Thursday, August 16, 2007 2:06 PM

An excellent post! This was very helpful. I really liked the grid layout in VS2003 - it made mock ups very simple. Thanks a lot for posting this!!

~MrGTI

# re: Absolute positioning in VS2005 HTML designer@ Thursday, September 06, 2007 3:35 PM

This was really useful. Thanks for posting this.

Chitra

# re: Absolute positioning in VS2005 HTML designer@ Sunday, September 16, 2007 2:41 AM

Thanks Kev,

very helpful. saved me lots of time

BigChris

# re: Absolute positioning in VS2005 HTML designer@ Wednesday, September 19, 2007 3:23 PM

Wow, amazing. It took me a day to find this.

Tan

# You love to shop?@ Monday, May 19, 2008 8:35 PM

Check out great daily deals!

You love to shop?

# re: Absolute positioning in VS2005 HTML designer@ Thursday, June 19, 2008 6:08 AM

Really nice post...i waster a day finding that option..

but now can move freely.. :) :)

Moni

# re: Absolute positioning in VS2005 HTML designer@ Sunday, October 12, 2008 7:24 AM

Thanks a lot. This was very helpful

Manu

# re: Absolute positioning in VS2005 HTML designer@ Tuesday, February 03, 2009 5:45 PM

Very useful tip that saves time... Thanks!

Raja

Leave a Comment

(required) 
(required) 
(optional)
(required)