Web development can sometimes be pretty repetitive. No, I am not talking about creating a lengthy online questionnaire that no sane person would ever fill out but rather the markup you have to write. To ease this pain, Microsoft has introduced a number of prewritten HTML and ASP.NET snippets (blocks of code) that will substantially reduce the amount of typing you have to do and minimize typos (and possibly reduce RSI in the web development community). I am a big believer in saving time spent on tedious tasks, so let's take a look into these snippets now.
Let's look at an example by following these steps:
Create a new ASP.NET project.
In Default.aspx, type textbox, and then quickly press Tab. Visual Studio will insert the following code:
<asp:TextBox runat="server" />
But wait—it gets better. Give your TextBox an ID of txtTest, and press Enter to add a new line.
Type requiredfieldvalidator, and press Tab.
Visual Studio will then insert the following markup. Note how the ControlToValidate property was set to the nearest text box automatically (if you add another text box to the page, you should still find this is the case) and how the cursor was focused on the ErrorMessage property. VS2010 will attempt to guess any properties it can (in this case because of the text box's proximity) and intelligently set the focus on any other fields that need to be filled in.
<asp:RequiredFieldValidator ErrorMessage="errormessage" ControlToValidate="txtTest" runat="server" />
The focus is currently set to the ErrorMessage property, so change it to You must fill in this field; then press Tab to move the focus to the next field.
Web development snippets are divided into two types: ASP.NET and HTML. Most of the snippets are pretty much self-explanatory; Table 10-1 describes some of the more cryptic ones.
A number of HTML snippets are also available. I would like to draw your attention to the XHTML doctype snippets, because I believe these are particularly useful, as shown in Table 10-2.
13.58.16.120