17
CSCI 6962: Server-side Design and Programming Master Pages

CSCI 6962: Server-side Design and Programming Master Pages

Embed Size (px)

Citation preview

Page 1: CSCI 6962: Server-side Design and Programming Master Pages

CSCI 6962: Server-side Design and Programming

Master Pages

Page 2: CSCI 6962: Server-side Design and Programming Master Pages

ASP and CSS

Implemented as a theme• Create App_Themes

directory• Create subdirectory with

stylesheet name• Copy stylesheet into

subdirectory• Copy other resources

(images, etc.) into subdirectory

Page 3: CSCI 6962: Server-side Design and Programming Master Pages

ASP and CSS

• Setting style for all pages: Add to web.config

<pages styleSheetTheme=“name of theme”/>

• Setting style for individual page: Add to <page tag

<%@ Page Language=“VB” StyleSheetTheme=“name of theme”/>

Page 4: CSCI 6962: Server-side Design and Programming Master Pages

ASP Master Pages

• Framework that allows other pages to be displayed inside of them as content

Master page Content

Page 5: CSCI 6962: Server-side Design and Programming Master Pages

Creating Master Pages

• Option in “New Item” List

Page 6: CSCI 6962: Server-side Design and Programming Master Pages

Master Page Contents

• Defines content common to all pages– Logo, navbar, etc.

• Can include dynamic content– Example: Current date

Page 7: CSCI 6962: Server-side Design and Programming Master Pages

Placeholder for Contents

• Must contain a ContentPlaceHolder object– Where content from other pages will be inserted– Two automatically added when Master Page created– Can always add more

Page 8: CSCI 6962: Server-side Design and Programming Master Pages

Linking Content Pages

• Can link existing content page to master page using Master Page property of page

• Check “Select Master Page” when adding new page– Can do later, but must strip out any html, body, form, and div tags

Page 9: CSCI 6962: Server-side Design and Programming Master Pages

Creating Content Pages

• New page appears inside master page in editor– Appears at location of ContentPlaceHolder– Master page content cannot be edited

Page 10: CSCI 6962: Server-side Design and Programming Master Pages

Creating Content Pages

• Page contents appear inside <asp:Content tag

Page 11: CSCI 6962: Server-side Design and Programming Master Pages

Creating Content Pages

• When run in browser, content page rendered inside master page

Page 12: CSCI 6962: Server-side Design and Programming Master Pages

Multiple Content Areas

• Can insert multiple ContentPlaceHolder on master page• Specify what goes in each area in content page

Page 13: CSCI 6962: Server-side Design and Programming Master Pages

Nested Master Pages

• Can nest one master page inside another– Outer = general content to all pages– Inner = specific content to some pages– As with content page, prompted for outer master page

Page 14: CSCI 6962: Server-side Design and Programming Master Pages

Nested Master Pages

• In editor, drawn inside outer master page in its ContentPlaceHolder

• Must have own ContentPlaceHolder to insert content from its client pages

Page 15: CSCI 6962: Server-side Design and Programming Master Pages

Nested Master Pages

• Specify inner master page as master page• Content rendered inside inner master page• Inner master page rendered inside outer master page

Page 16: CSCI 6962: Server-side Design and Programming Master Pages

Accessing Master Page Controls

• Client page can manipulate master page elements– More difficult, since not same object

• Basic steps:– Make master page control public to client page

• Create public method in code behind to manipulate control

– Set VirtualPath directive in client to refer to master page<%@ MasterType VirtualPath=“~/masterpage.master” %>

Page 17: CSCI 6962: Server-side Design and Programming Master Pages

Accessing Master Page Controls

• Example: – User enters name in content page– Greeting with name appears in master page