Master pages ppt

12,030 views

Published on

Published in: Education, Technology

Master pages ppt

  1. 1. Training on Master pages<br />Introducing Master pages<br />byPRAVEEN NANDAGIRI<br />
  2. 2. Agenda<br />Master Pages<br />Menu, Tree View Controls<br />Themes and Skins<br />Training on Master pages<br />
  3. 3. Training on Master pages<br />Master Page<br />Content Page<br />
  4. 4. On the left is a master page as seen in the Visual Studio 2005 IDE. On the right is a content page that uses that master page, also shown in Visual Studio. Note the rich design-time exeprience: when the content page is open in the designer, content declared in the page itself is shown in full color, while content inherited from the master page is shown in half-color. Master pages enable developers to build templates that contribute code and content to other pages ("content pages") on the site. Because ASP.NET 1.x lacked template support, developers often resorted to factoring common UI elements--elements that appear on multiple pages--into user controls and then declaring the user controls in each page that uses them. Master pages provide a more elegant solution to the problem of defining common look and feel. The term "visual inheritance" is often used to describe master pages because content pages inherit appearance from master pages the same way derived classes inherit methods, properties, and other type members from base classes.<br />Training on Master pages<br />
  5. 5. Training on Master pages<br />Masters define common content and placeholders (<asp:ContentPlaceHolder>)<br />Content pages reference masters and fill placeholders with content (<asp:Content>)<br />Site.master<br />default.aspx<br />http://.../default.aspx<br /><%@ Master %><br /><asp:ContentPlaceHolder<br /> ID="Main"<br /> RunAt="server" /><br /><%@ Page MasterPage-<br /> File="Site.master" %><br /><asp:Content<br /> ContentPlaceHolderID=<br /> "Main" RunAt="server" /><br /></asp:Content><br />
  6. 6. The first and most important concept to grasp when learning about master pages is that of Content and ContentPlaceHolder controls. Master pages use ContentPlaceHolder controls to define where content pages can plug in content. Content pages plug in content by declaring Content controls whose ContentPlaceHolderID properties match ContentPlaceHolder IDs in the master. A master page can contain an unlimited number of ContentPlaceHolder controls. All content defined in content pages MUST appear in Content controls--that is, between <asp:Content> and </asp:Content> tags.<br />Training on Master pages<br />
  7. 7. Master file “A.master”<br />Content file “B.aspx”<br />.<br />.<br /><<br />%<br />@ <br />Page <br /><<br />%<br />@ <br />Master <br />%<br />><br />Master<br />=<br />”A<br />.<br />master”<br />%<br />><br /><<br />asp<br />:<br />Content <br />runat<br />=<br />server <br />ContentName<br />=<br />”Main”<br />><br /><<br />/<br />asp<br />:<br />Content<br />><br /><<br />asp<br />:<br />Content <br /><<br />asp<br />:<br />ContentPlaceHolder <br />runat<br />=<br />server <br />runat<br />=<br />server <br />ContentName<br />=<br />”Footer”<br />><br />ContentName<br />=<br />”Main” <br />/<br />><br /><<br />/<br />asp<br />:<br />Content<br />><br /><<br />asp<br />:<br />ContentPlaceHolder <br />runat<br />=<br />server <br />ContentName<br />=<br />”Footer” <br />/<br />><br />Resulting Page<br />Training on Master pages<br />
  8. 8. Training on Master pages<br />This slide shows how to add a new item to a web site (here we add a master page)<br />
  9. 9. Training on Master pages<br />This slide shows how to give a name to a master page<br />
  10. 10. Training on Master pages<br />This slide shows that once you add a master page to a website how it looks (This is the sourse of master page)<br />
  11. 11. Training on Master pages<br />This slide shows that how to give a content placeholder to a master page<br />
  12. 12. Training on Master pages<br />This slide shows that design of the master page and it contains content place holder <br />
  13. 13. Defining a Master Page<br /><%@ Master Language="VB" %><br /><html><br /> <body><br /> <!-- Banner shown on all pages that use this master --><br /><table width="100%"><br /> <tr><br /> <td bgcolor="darkblue" align="center"><br /> <span style="font-size: 36pt; color: white">ACME Inc.</span><br /> </td><br /> </tr><br /> </table><br /> <!-- Placeholder for content below banner --><br /> <asp:ContentPlaceHolder ID="Main" RunAt="server" /><br /> </body><br /></html><br />
  14. 14. Master Pages: Creating a master page<br />1. Create a master page with .master extension<br />2. Define a master directive:<br /><%@ master .. %><br />3. Add content:<br />Can contain any html or control page content<br />Define replaceable place-holder regions:<br />Use an <asp:contentplaceholder> control<br />Add default content within it (optional)<br />
  15. 15. Modified Master Page<br /><%@ Master Language="VB" %><br /><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br /><script runat="server"><br /></script><br /><html xmlns="http://www.w3.org/1999/xhtml" ><br /><head runat="server"><br /> <title>Untitled Page</title><br /></head><br /><body><br /> <form id="form1" runat="server"><br /> <div><br /> &nbsp;<table border="0" cellpadding="0" cellspacing="0" style="width: 100%"><br /> <tr><br /> <td colspan="2" style="height: 100px"><br /> <img src="images/asp_net_logo.gif" /><br /> &nbsp; &nbsp; <span style="font-size: 24pt">Minder Chen ASP.NET Learning Web Site</span></td><br /> </tr><br /> <tr><br /> <td style="width: 49px" valign="top"> <br /> <asp:Menu ID="Menu1" runat="server"><br /> </asp:Menu><br /> </td><br /> <td><br /><asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"><br /> </asp:ContentPlaceHolder><br /> </td><br /> </tr><br /> </table><br /> </div><br /> </form></body></html><br />
  16. 16. Default Content<br />ContentPlaceHolder controls can define content of their own ("default content")<br />Default content is displayed ONLY if not overridden by content page<br /><%@ Master %><br /> ...<br /><asp:ContentPlaceHolder ID="Main" RunAt="server"><br /> This is default content that will appear in the absence of a<br /> matching Content control in a content page<br /><asp:ContentPlaceHolder><br />
  17. 17. Add a Content Page based on a Master Page<br />
  18. 18. Create a Content Page: Applying a Master Page<br /><%@ Page MasterPageFile="~/MasterPage.master" %><br /><asp:Content ContentPlaceHolderID="Main" RunAt="server"><br /> This content fills the content place holder "Main" defined in the master page (site.Master)<br /></asp:Content><br />
  19. 19. Using a Master Page<br />1. Create an ASP.NET page (.aspx extension)<br />2. On the page directive:<br /><%@ page masterpagefile= %> attribute to reference master<br />Set the title attribute <%@ Page title=“jeff” %><br />3. Optionally add content to override the master:<br />a. Only <asp:content> controls or server-side script allowed<br />b. <asp:content> controls replace regions in the master:<br />The contentplaceholderid identifies master’s region<br /><asp:content> controls can contain any page content<br />
  20. 20. A Content Page with a Master Page Applied<br />
  21. 21. Code for AboutUS.aspx<br /><%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="A bout US" %><br /><asp:Content ID="Content1" <br />ContentPlaceHolderID="ContentPlaceHolder1" <br />Runat="Server"><br /> <strong><span style="font-size: 14pt">This is a web site developed <br />by Minder Chen tohelp others to learn ASp.NET 1.X and 2.0. <br /> <br /><br /> He has used ASP.NET for more than 3 years by now and has <br />developed a Web-based DecisionSupport System using ASP.NET. He can be reached at minderchen@hotmail.com<br /> <br /><br /> </span></strong><br /></asp:Content><br />
  22. 22. Applying a Master Page to a Site<br /><configuration><br /> <system.web><br /> <pages masterPageFile="~/MasterPage.master" /><br /> </system.web><br /></configuration><br />
  23. 23. The Page.Master Property<br />Retrieves reference to master page<br />Instance of class derived from System.Web.UI.MasterPage<br />Null if page doesn't have a master<br />Used to programmatically access content defined in the master page<br />Use FindControl for weak typing<br />Use public property in master page for strong typing (preferred)<br />
  24. 24. Menu<br />200+ Properties; here are the top 4:<br />Orientation = Horizontal<br />StaticDisplayLevels = 2<br />StaticSubMenuIndent = 0<br />DisappearAfter = 300<br />
  25. 25. Menu Control Tag<br /> <asp:Menu ID="Menu1" runat="server" BackColor="#B5C7DE" DataSourceID="SiteMapDataSource1" DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98" Orientation="Horizontal" StaticSubMenuIndent="10px"><br /> <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" /><br /> <DynamicHoverStyle BackColor="#284E98" ForeColor="White" BorderStyle="Groove" /><br /> <DynamicMenuStyle BackColor="#B5C7DE" /><br /> <StaticSelectedStyle BackColor="#507CD1" /><br /><DynamicSelectedStyle BackColor="#507CD1" /><br /> <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" /><br /> <StaticHoverStyle BackColor="#284E98" ForeColor="White" /><br /></asp:Menu><br />
  26. 26. Menu or Tree: Choosing the right control<br />
  27. 27. Theme and Skin<br />
  28. 28. Add a Style Sheet in a Theme<br />
  29. 29.
  30. 30.
  31. 31. Style Builder – Build Style Rule<br />H1<br />{<br /> font-size: 30px;<br /> color: yellow;<br /> font-style: italic;<br /> font-family: 'Comic Sans MS';<br /> background-color: blue;<br /> font-variant: small-caps;<br />}<br />
  32. 32.
  33. 33. Apply Themes to the Web Site<br /><configuration><br /> <system.web><br /> <pages theme="ThemeName" /><br /> </system.web><br /></configuration><br />
  34. 34. To apply a theme to an individual page<br /><%@ Page Theme="ThemeName" %><br /><%@ Page StyleSheetTheme="ThemeName" %><br />
  35. 35. Themes: Architecture<br /> Themes are made up of a set of elements: skins, cascading style sheets (CSS), images, and other resources. At a minimum, a theme will contain skins. Themes are defined in special directories in your Web site or on your Web server.<br />Basically:<br />Inserts a link to your CSS Style Sheet<br />Updates properties on your controls<br />Two groups of files:<br />Your site – Nothing here changes<br />Theme A – Style Sheets, Images, Skins<br />At runtime these files are associated<br />
  36. 36. Themes: Recommended usage<br />Do as much as you can inside the Style Sheet<br />Foreground Images can’t be controlled by CSS, so use Skins<br />Advanced controls, use Skins<br />
  37. 37. Skin<br />
  38. 38. SkinFile.skin<br /><%--Default skin template. The following skins are provided as examples only.<br />1. Named control skin. The SkinId should be uniquely defined because<br /> duplicate SkinId's per control type are not allowed in the same theme.<br /><asp:GridView runat="server" SkinId="gridviewSkin" BackColor="White" ><br /> <AlternatingRowStyle BackColor="Blue" /><br /></asp:GridView><br />2. Default skin. The SkinId is not defined. Only one default <br /> control skin per control type is allowed in the same theme.<br /><asp:Image runat="server" ImageUrl="~/images/image1.jpg" /><br />--%><br /><asp:Button runat="server" <br /> BackColor="Red" <br /> ForeColor="White" <br /> Font-Name="Arial" <br /> Font-Size="9px" SkinID="Red" /><br /> <asp:Button runat="server" <br /> BackColor="Blue"<br /> ForeColor="Yellow" <br /> Font-Name="Arial" <br /> Font-Size="14px" /><br />
  39. 39.
  40. 40. Sample Code <br />You need to use Theme in order to use Skin<br /><%@ Page Language="VB" Theme="Theme1" <br />MasterPageFile="~/MasterPage.master" Title="Untitled Page" %><br /><script runat="server"><br />Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)<br />End Sub<br /></script><br /><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"><br /> <h1>Contact Information</h1><br /> Email: <br /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <asp:Button ID="Button1" SkinID="Red" runat="server" Text="Submit" /><br /> <asp:Button ID="Button2" runat="server" Text="Reset" /><br /></asp:Content><br />
  41. 41. Thank You !<br />

×