June 6, 2013

Master page in asp.net using Visual Studio 2010

Open Microsoft Visual Studio 2010.

Create a new website(am using visual c#).Choose ASP.NET Empty Web Site. You can change the file directory of your file. Just simply browse and name your folder where your file is being saved and click Ok.

Add a Master Page. To do that, in your solution explorer, right click the name of your website and choose Add new item.Choose MasterPage.master, the default name is MasterPage. Make sure that the check box is checked, only place code in a separate file, not to select master page.

This is how the code will look now.

Now edit the contents that often come in all pages the same. Here i am writing code for header, footer and side bar in MasterPage.

Next create a web form. This can be done by clicking your web site name, right click and Add new item. Choose C# and click Web Form. Make sure to check the select master page and Add.

Back to the Master Page, drag Content PlaceHolder from your toolbox in your Master Page.

In Solution Explorer, double click Home Web Form. When you notice your cursor, only ContentPlaceHolder is active, it means you could not write anything except the place holder. Now, we are going to put something in the place holder. Type “This is my Home Page”, do the same as what you created in your home web form and type that relate in every pages.

Save your work. See the output on your browser.


Popular Posts