DCSIMG
ASP.NET 4.0 New features – HTML, JS, ASP.NET Snippets - Pini Dayan

Pini Dayan

The best thing about a boolean is even if you are wrong, you are only off by a bit.

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

                                            image

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:

image 

 

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:

image

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.

image

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”
image 

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.

Comments

vvvlad said:

Hi,

Thanks for a good article.

One thing I would change is the title...

The features are part of VS2010 and has nothing to do with .NET 4.0

# December 1, 2009 2:00 AM

Pini Dayan said:

Hi thanks!

I agree but still its a nice feature relevant for ASP.NET....

# December 1, 2009 11:35 AM

Kristen Stewart's 'Welcome to the Rileys' Gets New Clip | Kristen Stewart Celebrity Monitor said:

Pingback from  Kristen Stewart's 'Welcome to the Rileys' Gets New Clip | Kristen Stewart Celebrity Monitor

# January 22, 2010 8:55 AM

Kristen Stewart's 'Welcome to the Rileys' Gets New Clip | Kristen Stewart Celebrity Monitor said:

Pingback from  Kristen Stewart's 'Welcome to the Rileys' Gets New Clip | Kristen Stewart Celebrity Monitor

# January 22, 2010 8:55 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: