Académique Documents
Professionnel Documents
Culture Documents
Project
Master pages help you define the overall layout of an ASP.NET application from a single location, the .master file, and then
reuse it in all the content pages that are derived from the master page
Master pages have the following features: The Master directive
Select the required items in the Add New Item dialog box
The ContentPlaceHolder controls on the specified master page are automatically referenced by using the Content controls on the new content page
to
departments, or groups on XHTML a Web site <!DOCTYPE html PUBLIC "-//W3C//DTD <asp:Content ID="Content1" 1.0 Transitional//EN" ContentPlaceHolderID="head" runat="Server"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1</asp:Content> transitional.dtd"> <asp:Content ID="Content2" <html Nested master pages have the following features: ContentPlaceHolderID="ContentPlaceHolder1" xmlns="http://www.w3.org/1999/xhtml"> runat="Server"> <head runat="server"> The .master file extension <asp:ContentPlaceHolder <title></title> ID="ContentPlaceHolder1" runat="server"> <asp:ContentPlaceHolder ID="head" </asp:ContentPlaceHolder> The Master directive runat="server"> </asp:Content> </asp:ContentPlaceHolder> Content controls that map to ContentPlaceHolder controls. In </head> <body> <%@has Page Title="" Language="C#" addition, the child master page its own ContentPlaceHolder <form id="form1" runat="server"> MasterPageFile="~/NesterMasterPage.master" <div> AutoEventWireup="true" controls. <asp:ContentPlaceHolder CodeFile="Default2.aspx.cs" ID="ContentPlaceHolder1" runat="server"> Inherits="Default2" %> </asp:ContentPlaceHolder> </div> You can view nested master pages in <asp:Content the Design ID="Content1" view in </form> ContentPlaceHolderID="ContentPlaceHolder1" </body> Runat="Server"> Visual Studio 2008 SP1 </html> </asp:Content>
Control
Features of user controls: Use the Control directive Consist of a user-defined Web server control Simplify the reuse of code and UI components in a Web application Do not contain the top-level HTML elementshtml, body, or form
Disadvantages
User controls are typically used for creating small units of layout and code that are used repeatedly within a Web application, such as login, validation, navigation, toolbars, and similar functionality
Remove all top-level HTML elements Change the Page directive to the Control directive Add a ClassName attribute to the Control directive Change the file extension from .aspx to .ascx Change the class type to UserControl Add the properties
Best Practices