Chapter 14: Fun Pet Tricks


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!

Fun Pet Trick #1: HTML Source Preservation

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:

  1. Create a new ASP.NET page.

  2. Paste the following code into Source view (notice that the button is custom formatted in a nondefault way to have one attribute per line):

     <%@ page language="VB" %> <html> <body>     <form runat="server">         <asp:button                      runat="server"                     text="Button"                     backcolor="Red"                     font-italic="True" />     </form> </body> </html> 

  3. Switch to design mode.

  4. Type some text before the button, press Enter, put the cursor after the button, press Enter, type some more text.

  5. 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                      runat="server"                     text="Button"                     backcolor="Red"                     font-italic="True" />         <br />         <br />         some more random text     </form> </body> </html> 

  6. Flip back to design mode, select the button, and then change the text property in the Properties grid.

  7. 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:

     <%@ page language="VB" %> <html> <body>     <form runat="server">         Some random text<br />         <br />         <asp:button                      runat="server"                     text="Push Me"                     backcolor="Red"                     font-italic="True" />         <br />         <br />         some more random text     </form> </body> </html> 

Cool stuff. You can now use the design surface with confidence.




ASP. NET 2.0 Revealed
ASP.NET 2.0 Revealed
ISBN: 1590593375
EAN: 2147483647
Year: 2005
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net