Escolar Documentos
Profissional Documentos
Cultura Documentos
Introduction
Main menu Style and script links Common HTML header information Layout, header, footer, logo, etc.
Common site level contents should be easily and flexibly developed and maintained
Usually requires the development and maintenance at the site level, rather than at the page level.
2
Basic Approaches
Hybrid Approach
Template + Modules
Basic Techniques
Client side
Server Side Includes (SSI) is a web scripting language (not ASP.Net exclusive) to include the contents of one or more files into a web page
Frequently used for content modulation SSI can include HTML files, source code file, and other raw file source. Note that whats included is the source code, not the generated content.
This SSI script can be put anywhere in the web page (where the content of header.htm should be inserted.)
Example
http://en.wikipedia.org/wiki/Server_Side_Includes
8
SSI Limitations
SSI scripts are evaluated before ASP.Net framework code or, included files are processed and inserted before the scripts are executed.
<% NOT Working! string fname="header.aspx"; %> <!--#include file="<%= fname%>"--> <!--#include file="header.aspx?choice=1" -->
SSI is problematic to work with dynamic ASP.Net pages (aspx files with .Net code)
9
Response.WriteFile()
The included file content are processed and inserted after the scripts are executed.
The raw source is directly inserted without additional processing, which is not appropriate in this context. Use static content file instead.
Example
Response.WriteFile("header.aspx")
Server.Execute()
Server.Execute() can return a files execution restuls (content) in the current context.
Whats included is not the raw source, but the execution results.
Reference:
http://msdn.microsoft.com/enus/library/system.web.httpserverutility.execute.aspx
11
User Controls
User controls are containers into which you can put markup and Web server controls. A user control can be treated as a unit and be reused in different pages. User controls work in a similar way as SSI, only with richer functionalities.
12
<h1>This is a user control</h1> <asp:Image ID="Image1" runat="server" /> <%= Request.QueryString[0] %> A user control consists of
The query string is from the URL of its container page.
HTML tags, web server controls, and code.
13
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <body> <form id="form1" runat="server"> <uc1:links ID="links1" runat="server" /> <div></div> </form> </body></html>
Insert the user control just like SSI to where it is actually needed.
14
Master Page
ASP.NET master page is a web page template that defines the common elements and behaviors of many pages. A web page that implements the master page consists of two pieces
The master page itself Content pages: which contains the page specific content
When content pages are requested, master pages and content pages are merged
The output combines the layout of the master page with the content from the content page.
16
In addition to static text and controls that will appear on all pages, the master page also includes one or more ContentPlaceHolder controls. These placeholder controls define regions where replaceable content will appear.
2. Add text and controls to Content controls. In a content page, anything that is not inside the Content controls (except script blocks for server code) results in an error. You can perform any tasks in a content page that you do in an ASP.NET page. For example, you can generate content for a Content control using server controls and database queries.
When a content page is requested, its content is merged with the master page, and the page runs in the context of the content page.
17
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="it4203.master.cs" Inherits="MasterPage_it4203" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <asp:ContentPlaceHolder id="head" runat="server"></asp:ContentPlaceHolder> </head>
A place holder is defined in the head section.
<body> <form id="form1" runat="server"> <h2>IT 4203 - Fall 2010</h2><h1>Advanced Web Development</h1> <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server> </asp:ContentPlaceHolder> <p id="footer">2010 Jack G. Zheng</p> A place holder is defined in the body section. </form> </body></html>
18
<%@ Page Title="IT 4203" Language="C#" MasterPageFile="~/it4203.master" AutoEventWireup="true" CodeFile="it4203-contentpage.aspx.cs" Inherits="structure_it4203_contentpage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> </asp:Content>
A place holder is created corresponding to the one defined in the master page, but without any content.
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <h2>Course Description</h2> <p>This course covers more advanced topics on web application development including server-side programming ...</p> </asp:Content>
Create some page specific content in the second place holder. No other elements are outside place holders.
19
The master page and content page do not have to be in the same folder.
This can affect how you specify relative paths for resources, such as image files and target pages, in anchors.
The context for the merged content page and master page is that of the content page. In general, when working with elements on master pages, it is recommended that you use a server control, even for elements that do not require server code.
In server controls on master pages, ASP.NET dynamically modifies the URLs of properties that reference other resources.
20
Master page is a direct implementation of the template approach for common web site elements
They allow you to centralize the common functionality of your pages so that you can make updates in just one place. They make it easy to create one set of controls and code and apply the results to a set of pages. They give you fine-grained control over the layout of the final page by allowing you to control how the placeholder controls are rendered. They provide an object model that allows you to customize the master page from individual content pages.
21
Application Path
Use this operator with server controls where path information is needed
In your application, you might need to determine the path of a file or other resource on the server. See http://msdn.microsoft.com/en-us/library/ms178116(v=VS.90).aspx
Server.MapPath(string virtualpath) Example: Server.MapPath("~") returns the physical path of the application root directory defined in IIS, which could be C:\inetpub\wwwroot\student\demo\
22
Web Navigation
Web navigation (moving from page to page) can be initiated by user actions such as clicking on a link/button or submitting a form
Server.Trasfer() Response.Redirect()
23
Summary
Key concepts
Server Side Includes User controls Master page and content page
Key skills
Know the different approaches and techniques to develop and maintain the common content blocks of a website. Apply master pages for the common look and feel of a website.
24
http://en.wikipedia.org/wiki/Server_Side_Includes
http://msdn.microsoft.com/en-us/library/y6wb1a0e(v=VS.85).aspx
http://msdn.microsoft.com/en-us/library/wtxbf3hh(v=VS.90).aspx
http://msdn.microsoft.com/en-us/library/ms178116(v=VS.90).aspx
25