ASP.NET 4.0 New features – HTML, JS, ASP.NET Snippets

In previous version of VS.NET we encountered the new snippet solution for creating a chunk of code that is usually reusable and then using it during programming or even lecturing. This feature was available for both C# and VB.NET coders. But we could not create or use snippets for the markup we are writing like HTML, JavaScript or even the ASP.NET page. VS.NET 2010 allows us to do just that!
Lets see some of the “out of the box” snippets we can use:
HTML Snippets:
AS you can see the same snippet sign is now available on the ASPX page side. So for example if I choose the checkbox snippet and double tab click it i will get the following markup:

JavaScript Snippets:
Let move even further and see a much useful sample. Most of us are writing JavaScript and lots of it in our web application, so lets see what is available out of the box for us in JavaScript :
alert snippet,control snippet,create snippet, do for while snippets, if else snippets and much much more. Here for example I am using the for snippet for creating a for clause.
ASP.NET snippets:
We have some useful control declarations as a snippets such as updatepanel, sqldatasource , all the validator controls and much much more.
Creating our own custom snippets:
Wouldn’t it be great to create our own snippets since we are the ones knowing what markup we most commonly using. So before showing how to accomplish this, Here is how you can see the entire list of snippets.
In the VS.NET 2010 , clicj the tool menu and open the “code snippets manager”
This snippet manager will now show you all the HTML, ASP.NET snippets or the JS snippets if you choose Jscript in the language select box. So in order to add them simply use this manager and read how to create the snippet files here.
Surround with feature:
Another cool thing we have in C# and is really useful is the “surround with” . We can for example write some JS code and then decide we want to surround it with a function. Simply select the wanted Js , right click and choose “surround with” .
Enjoy.