This chapter offers a series of so-called Fun Pet Tricks that were originally published in the protected Alpha forums for Whidbey by Scott Guthrie and myself. These tricks will give you interesting insights to various features of the new version of ASP.NET and can in most cases be adopted within minutes. Some of my own Fun Pet Tricks have been created during the work on this book, and I've directly embedded them in chapters with related topics rather than list them in this chapter.
Many thanks to Scott, who allowed the publication of his samples. You can definitely find more of my tricks in the forums of www.asp.net in the near future. I hope you enjoy them!
By Scott Guthrie
One of the biggest new features of Visual Studio Whidbey is the fact that the designer no longer reformats or rearranges your HTML source code.
To see a fun example of this in action, try these steps:
Create a new ASP.NET page.
Paste the following code into Source view (notice that the button is custom formatted in a nondefault way to have one attribute per line):
Switch to design mode.
Type some text before the button, press Enter, put the cursor after the button, press Enter, type some more text.
Flip back to source mode. The code now looks as follows (notice the button wasn't reformatted):
<%@ page language="VB" %> <html> <body> <form runat="server"> Some random text<br /> <br /> <asp:button id="Button1" runat="server" text="Button" backcolor="Red" font-italic="True" /> <br /> <br /> some more random text </form> </body> </html>
Flip back to design mode, select the button, and then change the text property in the Properties grid.
Flip back to source mode and notice that even when the button text was updated, the designer did not reformat the indentation of the attributes:
Cool stuff. You can now use the design surface with confidence.