Click here to Skip to main content
15,885,546 members
Articles / Web Development / ASP.NET
Tip/Trick

Creating Reusable Page template

Rate me:
Please Sign up or sign in to vote.
4.92/5 (7 votes)
23 Oct 2013CPOL2 min read 15.5K   14  
Here we’ll learn how to create a page template of our own that is reusable.

Introduction

In this article we'll built a customized page template instead of using the built-in Web Form Template.

Background  

When developing any web application we most of the times use the built-in Web Form that's with the Visual Studio. But What if we want to have a Web Form that we will design as we want and keep it as a template for reuse. So lets do something like that by following the steps below.

Steps     

  1. First of all Open VS2012, click on New Project on start page or go to File ->New -> Project.

 Image 1

  1. From the left bar Templates select Visual C# -> Web and then in right side select ASP.NET Empty Web Application. Let’s name our application MyWebApplication and set the location of it. Then Press OK.   

Image 2

  1. From Solution Explorer right click on the project template and select New Item.

Image 3

  1. Click on Web Form and name it MyWebForm.aspx and click Add.  

Image 4 

  1. In the Markup View set the <title> attribute as follows <title>My Web Form</title>, add <h1>Hello everyone, this is my web form</h1> inside the <div></div> that’s within the <form></form>.So now what if you want this MyWebForm.aspx to be the default Web Form that you can use when you want to add a new one. Save all your changes.  

Image 5

  1. Go to File -> Export Template, select Item template option from the radio buttons and from the DropDownList select the project from which you would like to create the template. In our case it’s MyWebApplication. Click Next.

Image 6

Image 7

  1. Select the item that you want to export as item template. In our case its MyWebForm.aspx . Click Next.

Image 8

  1. From the select item reference dialogue select nothing. Click Next.

Image 9

  1. From Select Template Option dialogue give Template Name as MyDefaultWebForm and a description about that template. And check both the checkboxes below. Click Finish
Image 10
  1. Check if the folder exists here : C:\Users\helloBug\Documents\Visual Studio 2012\Templates\ItemTemplates Change helloBug with your User name.  

Image 11

  1. Now right click on the Project Template Add New Item and see your template has been added in Visual C#. You’ll also find the description on the right side.  

Image 12

  1. Click on MyDefaultWebForm1 template on right side name it as you like. I’ll take the default one. And click Add.
  2. It might show you a warning. You might read it. To Continue Click Trust.

Image 13

So this is it. Now you have your own page template to use.

Note: you may have to restart VS and reopen your website for the template to appear.

Hope you learned something. Thank you.  

This article was originally posted at http://www.babycoders.com?p=67

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Secure Link Services
Bangladesh Bangladesh
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --