Click here to Skip to main content
11,438,226 members (61,861 online)
Click here to Skip to main content

Creating Reusable Page template

, 23 Oct 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
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.

 

  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.   

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

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

 

  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.  

  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.

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

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

  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
  1. Check if the folder exists here : C:\Users\helloBug\Documents\Visual Studio 2012\Templates\ItemTemplates Change helloBug with your User name.  

  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.  

  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.

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.  

License

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

Share

About the Author

Ashad Shanto
Student
Bangladesh Bangladesh
No Biography provided
Follow on   Google+   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150506.1 | Last Updated 23 Oct 2013
Article Copyright 2013 by Ashad Shanto
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid