Académique Documents
Professionnel Documents
Culture Documents
Themes
Manage the CSS. Manage the skin of your site
Master Pages
Master Page Content Page
Site.master
<%@ Master %>
default.aspx
<%@ Page MasterPageFile="Site.master" %> <asp:Content ContentPlaceHolderID= "Main" RunAt="server" />
http://.../default.aspx
</asp:Content>
< % @ Master
%>
ContentName
= Footer
/>
< / asp : Content >
3. Add content:
Can contain any html or control page content Define replaceable place-holder regions:
Use an <asp:contentplaceholder> control Add default content within it (optional)
<script runat="server"> </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <table border="0" cellpadding="0" cellspacing="0" style="width: 100%"> <tr> <td colspan="2" style="height: 100px"> <img src="images/asp_net_logo.gif" /> <span style="font-size: 24pt">Minder Chen ASP.NET Learning Web Site</span></td> </tr> <tr> <td style="width: 49px" valign="top"> <asp:Menu ID="Menu1" runat="server"> </asp:Menu> </td> <td>
Default Content
ContentPlaceHolder controls can define content of their own ("default content") Default content is displayed ONLY if not overridden by content page
<%@ Master %> ... <asp:ContentPlaceHolder ID="Main" RunAt="server"> This is default content that will appear in the absence of a matching Content control in a content page <asp:ContentPlaceHolder>
Site Navigation
Navigation UIs are tedious to implement
Especially if they rely on client-side script
Menu
TreeView
SiteMapPath
SiteMapNode
Providers
XmlSiteMapProvider
Site Maps
Web.sitemap Other Data Stores
Navigation
<?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNode url="" title="" description=""> <siteMapNode url="" title="" description="" /> <siteMapNode url="" title="" description="" /> </siteMapNode> </siteMap> Minder Chen, 1994-2006 Master page & Navigation - 25
Web.sitemap
XML document is "very" case sensitive
<?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNode url="Default.aspx" title="Home" description="Home Page"> <siteMapNode url="Assignments.aspx" title="Assignments" description="Programming assignments"> <siteMapNode url="Assignment1.aspx" title="Assignment 1" description="Programming assignment 1" /> <siteMapNode url="Assignment2.aspx" title="Assignment 2" description="Programming assignment 2" /> </siteMapNode> <siteMapNode url="AboutUs.aspx" title="About Us" description="Authors and purposes"> <siteMapNode url="ContactInfo.aspx" title="Contact information" description="Contact phones and emails" /> <siteMapNode url="ManagementTeam.aspx" title="Management Teams" description="Introduction of management teams" /> </siteMapNode> </siteMapNode> </siteMap>
SiteMapDataSource
Data source control representing site maps
Site map = List of pages and URLs Nodes can include descriptive text
Permits TreeViews and Menus to be populated with links through data binding Supports "security trimming"
Specified nodes visible only to specified roles
Menu
200+ Properties; here are the top 4:
Orientation = Horizontal StaticDisplayLevels = 2 StaticSubMenuIndent = 0 DisappearAfter = 300
</asp:Menu>
SiteMapPath Controls
"Bread crumbs" showing path to page
By default, renders current node as static text By default, renders parent nodes as hyperlinks
Highly customizable UI
Nodes can be stylized and templatized Separators can be stylized and templatized
Stylizing SiteMapPath
<asp:SiteMapPath Font-Name="Verdana" Font-Size="10pt" RunAt="server"> <CurrentNodeStyle Height="24px" BackColor="Yellow" Font-Bold="true" /> <NodeStyle Height="24px" /> <PathSeparatorTemplate> <ItemTemplate> <asp:Image ImageUrl="~/images/arrow.gif" RunAt="server" /> </ItemTemplate> </PathSeparatorTemplate> </asp:SiteMapPath>
Features
Expansion Download on Demand Checkboxes
Menu
PopOut No No
Treeview
Expand in Place Yes Yes
Templates
Layout Mobile & Downlevel Style Option Selection Model
Yes
Horizontal & Vertical Yes Static, Dynamic, Level Link & Hover
No
Vertical Yes Level or Parent/Root/Leaf by data item Postback, link & disabled
Themes: Architecture
Basically:
Inserts a link to your CSS Style Sheet Updates properties on your controls
Skin
SkinFile.skin
<%-- Default skin template. The following skins are provided as examples only. 1. Named control skin. The SkinId should be uniquely defined because duplicate SkinId's per control type are not allowed in the same theme. <asp:GridView runat="server" SkinId="gridviewSkin" BackColor="White" > <AlternatingRowStyle BackColor="Blue" /> </asp:GridView> 2. Default skin. The SkinId is not defined. Only one default control skin per control type is allowed in the same theme. <asp:Image runat="server" ImageUrl="~/images/image1.jpg" /> --%>
<asp:Button runat="server" BackColor="Red" ForeColor="White" Font-Name="Arial" Font-Size="9px" SkinID="Red" /> <asp:Button runat="server" BackColor="Blue" ForeColor="Yellow" Font-Name="Arial" Font-Size="14px" />
Minder Chen, 1994-2006 Master page & Navigation - 46
Sample Code
You need to use Theme in order to use Skin <%@ Page Language="VB" Theme="Theme1" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <h1>Contact Information</h1>
Email:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" SkinID="Red" runat="server" <asp:Button ID="Button2" runat="server" Text="Reset" /> </asp:Content>
Minder Chen, 1994-2006 Master page & Navigation - 48
Text="Submit" />
UITricksTips.aspx
<%@ Page Language="VB"
MaintainScrollPositionOnPostback="true" %>
<script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) LabelMsg.Text = "" LabelDefault.Text = "" If IsPostBack Then
TextBoxPassword.Focus()
End If End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) LabelMsg.Text = "Thank you for testing this. Please continue!" End Sub Protected Sub ButtonDefault_Click(ByVal sender As Object, ByVal e As System.EventArgs) LabelDefault.Text = "You click the default button!" End Sub </script> <script>
Continued
<div> <asp:Label ID="LabelUserName" runat="server" Text="<u>U</u>ser Name:" AssociatedControlID="TextboxUserName"></asp:Label> <asp:TextBox ID="TextBoxUserName" AccessKey="u" runat="server" AutoCompleteType="displayName" /> <asp:RequiredFieldValidator ID="RequiredFieldValidatorUserName" runat="server" ErrorMessage="User name for secured login" ControlToValidate="TextboxUserName" ValidationGroup="userlogin" ></asp:RequiredFieldValidator> <br /> <asp:Label ID="LabelPassword" runat="server"
AccessKey="p" AssociatedControlID="TextboxPassword"
Text="<u>P</u>assword:"></asp:Label> <asp:TextBox ID="TextBoxPassword" runat="server" > </asp:TextBox> <br /> <asp:Button ID="buttonSumit" runat="server" Text="Secured Login" ValidationGroup="userlogin" /> <br /> <br /> <br /> <br /> <asp:Label ID="LabelEmail" runat="server" AccessKey="p" AssociatedControlID="TextboxEmail" Text="<u>E</u>mail:"></asp:Label><asp:TextBox ID="TextBoxEmail" runat="server"> </asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Email is required for login with email" ControlToValidate="TextboxEmail" ValidationGroup="email" ></asp:RequiredFieldValidator> <br /> <asp:Button ID="buttonLoginWithEmail" runat="server" Text="Login with Email" ValidationGroup="email" OnClientClick="HelloAlert();" /> <br /> <asp:Image ID="Image1" runat="server" AlternateText="ASP.NET Logo" ImageUrl="~/images/asp_net_logo.gif" DescriptionUrl="~/AboutUs.aspx" /><br /> <br /> Minder Chen, 1994-2006 Master page & Navigation - 51
Continued
<asp:Button ID="ButtonDefault" runat="server" Text="Default Button" OnClick="ButtonDefault_Click" /> <asp:Label ID="LabelDefault" runat="server"></asp:Label><br />
Test<br /> Test<br /> Test<br /> Test<br /> Test<br /> Test<br /> Test<br /> Test<br /> Test<br /> Test<br /> Test<br /> Test<br /> Test<br /> Test<br /> Test<br /> Test<br /> Test<br /> Test<br /> Test<br />
TreeView Controls
Render hierarchical data as trees
Expandable and collapsible branches Nodes are navigable, selectable, or static and can include check boxes
Highly customizable UI
Declaring a TreeView
<asp:TreeView RunAt="server> <Nodes> <asp:TreeNode Text="Training" RunAt="server"> <asp:TreeNode Text="Programming .NET" RunAt="server" Navigateurl="Classes.aspx?id=1" /> <asp:TreeNode Text="Programming ASP.NET" RunAt="server" NavigateUrl="Classes.aspx?id=2" /> <asp:TreeNode Text="Programming Web Services" RunAt="server" NavigateUrl="Classes.aspx?id=3" /> </asp:TreeNode> <asp:TreeNode Text="Consulting" RunAt="server" NavigateUrl="Consulting.aspx" /> <asp:TreeNode Text="Debugging" RunAt="server" NavigateUrl="Debugging.aspx" /> </Nodes> </asp:TreeView>
Name
ExpandDepth ShowExpandCollapse LevelStyles NodeStyle RootNodeStyle
Description
Specifies the TreeView's initial expand depth Specifies whether expand/collapse indicators are shown Specifies appearance of nodes by level Specifies default appearance of nodes Specifies appearance of root nodes
LeafNodeStyle
SelectedNodeStyle HoverNodeStyle Minder Chen, 1994-2006
Web.sitemap
<siteMap> <siteMapNode title="Home" description="" url="default.aspx"> <siteMapNode title="Training" url="Training.aspx" description="Training for .NET developers"> <siteMapNode title="Programming .NET" url="Classes.aspx?id=1" description="All about the .NET Framework" /> <siteMapNode title="Programming ASP.NET" url="Classes.aspx?id=2" description="All about ASP.NET" /> <siteMapNode title="Programming Web Services" url="Classes.aspx?id=3" description="All about Web services" /> </siteMapNode> <siteMapNode title="Consulting" url="Consulting.aspx" description="Consulting for .NET projects" /> <siteMapNode title="Debugging" url="Debugging.aspx" description="Help when you need it the most" /> </siteMapNode> </siteMap>
<configuration> <system.web> <siteMap> <providers> <remove name="AspNetXmlSiteMapProvider" /> <add name="AspNetXmlSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, ..." siteMapFile="Acme.sitemap" /> </providers> </siteMap> </system.web> </configuration>
<siteMapNode> Attributes
Name
description roles title url
Description
Description of node Role or roles for which this node is visible* Title of this node URL of this node
Security Trimming
Visible to everyone
<siteMap> <siteMapNode title="Home" description="" url="default.aspx"> <siteMapNode title="Announcements" url="Announcements.aspx" description="Information for all employees" roles="*" /> <siteMapNode title="Salaries" url="Salaries.aspx" description="Salary data" roles="Managers, CEOs" /> <siteMapNode> </siteMap>
<configuration> <system.web> <siteMap> <providers> <remove name="AspNetXmlSiteMapProvider" /> <add name="AspNetXmlSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, ..." securityTrimmingEnabled="true" siteMapFile="web.sitemap" /> </providers> </siteMap> </system.web> </configuration>
SiteMapDataSource Properties
Name
Provider SiteMapProvider ShowStartingNode StartFromCurrentNode
Description
Provider used to obtain site map data Name of provider used to obtain site map data Specifies whether to show the root node Specifies whether starting node should be the root node (false) or the current node (true). Default = false Starting node identified by level (default = 0) Starting node identified by URL
StartingNodeOffset StartingNodeUrl
Web.sitemap
<siteMap> <siteMapNode title="Home" description="" url="default.aspx"> <siteMapNode title="Training" url="Training.aspx" description="Training for .NET developers"> <siteMapNode title="Programming .NET" url="Classes.aspx?id=1" description="All about the .NET Framework" /> <siteMapNode title="Programming ASP.NET" url="Classes.aspx?id=2" description="All about ASP.NET" /> <siteMapNode title="Programming Web Services" url="Classes.aspx?id=3" description="All about Web services" /> </siteMapNode> <siteMapNode title="Consulting" url="Consulting.aspx" description="Consulting for .NET projects" /> <siteMapNode title="Debugging" url="Debugging.aspx" description="Help when you need it the most" /> </siteMapNode> </siteMap>
Using SiteMapPath
Name
CurrentNodeStyle CurrentNodeTemplate NodeStyle NodeStyleTemplate PathSeparator
Description
Style used to render the current node HTML template used to render the current node Style used to render non-current nodes HTML template used to render non-current nodes Text used for node separators (default = ">")
PathSeparatorStyle
PathSeparatorTemplate
' Write the title of the current node to a Label control Label1.Text = SiteMap.CurrentNode.Title ' Write the path to the current node to a Label control Dim node As SiteMapNode = SiteMap.CurrentNode Dim builder As New StringBuilder (node.Title) While Not (node.ParentNode Is Nothing) node = node.ParentNode builder.Insert (0, " > ") builder.Insert (0, node.Title) End While Label1.Text = builder.ToString ()
SiteMap.ResolveSiteMap
Fired by SiteMapPath controls Used to perform on-the-fly customization of paths displayed by SiteMapPath controls
Add nodes to site map for pages that don't appear in the site map Change the properties of the current node