Eliminating Aspnet WebForms Redundant Coding with Snippets

I know that Aspnet web form are kinda old school now a days with MVC 3 in the picture, but I wanted to share a way I have used in all my project to increase productivity.  There are .cs codebehind pages that you use in a every aspx file that you always have to deal with postback.

A great way to not waste time typing the same code over and over again is to use snippets in visual studios.

One that I use on just about every page that has code behind is this series of syntax:

protected void Page_Load(object sender, EventArgs e)

if (!Page.IsPostBack)


protected void Page_Init(object sender, EventArgs e)


This handles postbacks in your page and sets up the on page initialize, in which you can use to wire up events for your buttons, dropdownlists, datagrids, dataviews, ect.

Here is my snippet to use at your own discretion, I asked that you please dont modify the author out of personal copyright credit.


Just unzip snippet and drop it in the directory listed below.  Then when in your codebehind  (.cs file) simply type:

“pageload” then hit the TAB Key twice.

Installation path: “C:\Users\ahicksdev\Documents\Visual Studio 2010\Code Snippets\Visual C#\My Code Snippets”

Feel free to post any snippets that you have found useful in your development experience.

Thanks in advance for sharing!  🙂




About Art Hicks

I am Business Owner/Applications Engineer that specializes in providing rich solutions to my clients and colleagues.
This entry was posted in .NET, ASP.NET, C#, snippet, Web Design and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s