Saturday 31 October 2009

C# asp.Net Master Page

In .Net 2.0 and above there are Master pages in asp.Net. Create a master page such as a header and footer that you want across the site and then on the master page add the contentplaceholder tag to mark a point where content will be added to the master page.






Then on the asp web pages for the site add put all the code in content tags setting the contentplaceholderID attribute to the id of the contentplaceholder in the master page.


<asp:content id="Content1" runat="Server" contentplaceholderid="ContentPlaceHolder1">
<span>Hello</span>
</asp:content>


When the browser requests the page the content in the content tag of the asp page will be inserted into the master page at a point according to the contentplaceholder ID. The approach is flexible because it allows for lots of options in the places the data is inserted into the main page. For example you could have two different point in the master file where code was inserted.

No comments:

Post a Comment