Mink Machine

Visual Studio tips for web developers

I’ve used Visual Studio in its various incarnations since 1998 and despite all short-comings I still think it’s one of the most powerful IDEs out there. There are many people who are introduced to Visual Studio today, so here are some small beginner’s tips I want to share to new ASP.NET developers.

Use server-side comments for aspx pages

I often see HTML comments used on aspx pages, like this:

<!– <asp:Literal ID=”MyLiteral” runat=”server” /> –>

One of the downsides of this method is that the comments will be visible to anyone viewing the markup of the rendered page, and unnecessary bytes will have to be transferred to the browser. Use server-side comments instead:

<%– <asp:Literal ID=”MyLiteral” runat=”server” /> %>

This will prevent the content from being rendered at all. Unfortunately server-side comments seems to be almost unknown to the developer community but they have actually been there since Visual Studio 2005.

Note that the HTML comment style is still used for certain file types, such as web.config. If you are unsure of what comment style to use, Visual Studio can do the thinking for you. Just use the keyboard shortcut Ctrl+E,C and uncomment with Ctrl+E,U. (Keyboard mappings can be different on your machine depending on environment setup.)

Set source mode to default

I really hope this one is default for everyone by now, but just to be sure. Your aspx page can be viewed in two modes: Design and Source. Design mode will hide your markup code while doing a poor job as a drag-n-drop layout tool. This is the default mode for many installations, but try to stay away from it or your markup will most likely be cluttered with non-compliant code.

Learn the shortcuts

Keyboard shortcuts are a real time-saver in complex IDEs. You probably know about the usual ones but there are some hidden gems.

For instance, Ctrl+- returns you to previous cursor location. This even works across different open files and can be nice to have for returning after Go To Definition (F12) or similar. Visual Studio saves your locations on a stack so it can be used multiple times.

Another time-saver is the fact that usual copy-paste (Ctrl+X/C/V) works even without anything being marked. Just position your cursor on a line and hit Ctrl+X to erase the entire line, no marking needed.

Custom snippets

If you frequently type certain chunks of code, snippets may be useful. There are several pre-made ones available out of the box. For instance, if you need a property, just type prop (a unique identifiable part of the snippet shortcut name) and hit Tab twice for completion to get a code skeleton with fields for changing type and names. It’s a templated snippet so you can advance to next field by pressing Tab and move to previous by Shift+Tab.

You can view all available snippets in the Snippet Manager (Ctrl+K, Ctrl+B). Snippets are simple XML files and located in the Visual Studio program folder, so you can easily modify them or create your own.

Use correct placeholders

If you need a container or wrapper for a piece of code, I recommend using an <asp:PlaceHolder> instead of <asp:Panel>. The latter will insert an extra <div> in your markup which will likely lead to irritation and debugging if you’re not aware of it.


Once you hit a breakpoint, it’s common to step forward using F10/F11. But don’t forget the “run to cursor” feature, which may save some time. You may also set conditions on your breakpoints by right-clicking the red dot and select “Condition”. The “Hit Count” feature may also be useful while debugging loops. If you want to evaluate a statement, type it in the “Immediate window”.

Happy coding!


No comments yet.

Post a comment

Your email address will not be published. Required fields are marked *

Featured stories

Alone in Kyoto

"I tried my best to sneak across the building, but the floor revealed me each time. I suppose I would make a lousy ninja."

Aliens in Nevada and New Mexico

"We turned around and went down another dirt road, past countless Joshua trees until our car was covered in dirt and we finally arrived at the Front Gate of Area 51."

Sessions in Seville

"I end my journey in front of the tomb of Columbus, located inside the world’s largest Gothic cathedral."

The urban maze of Tangier

"There are exciting things waiting around every corner and my bucket list is long, but the Medina has a mindset of its own regarding time and space."

Chilling in Chile

"My weary feet has reached Valparaiso. After almost a month of traveling across the South American continent I realize that this is as far south as I will come, due to weather conditions."

On the Trans-Siberian

"Since the toilets were locked during the seven hour stop, we had to bribe the provodnitsas to use the facilities. Then came the Mongols."