Saturday, 22 December 2012 13:55

master pages in asp.net

Written by 
Rate this item
(0 votes)

master pages creates a common look in your application.
if we think about the header and footer in our pages,we
create these header and footer in every aspx pages.this
method has disadvantages.if there were any custom page
which dynamically adds header and footer then would be
good.

in Asp.net,this can be achieved by the built in
MasterPages.

a masterpage is same to a .aspx but it has its own
extension .master.this page also contains a master
directive and a contentplaceholder control.
this contentplaceholder control is content area
placeholder where content pages inject data.
a masterpage can hold many contentplaceholder with
respective id's so that correct contentplaceholder is
referenced with it's id.

as a example take a look the following codes for a
master page.

<%@ Master Language=�C#� %>
<html>
<head><title>Master Page Tutorial on my blog</title>
<body>
<form runat=server>
<asp:ContentPlaceHolder ID=�ContentPlaceHolder1� runat=�server�>
<h1>default content</h1>
</asp:ContentPlaceHolder>
</form>
</body>
</html>

after the masterpage is created one can create pages from this
master page template.this content page is look like same
as other content pages but in page directive it will
reference master page and also contains a control and within
this control will be all your data along with content of
corresponding contentplaceholder control in master page.

a example follows with the master page i created above -

<%@ Page Language=�C#� MasterPageFile=�~/demo.master� %>
<asp:Content id=�content� ContentPlaceHolderID=�ContentPlaceHolder1� runat=�server�>
<h1>default content.more content is added</h1>
</asp:Content>

Read 2886 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.