Marco Bellinaso - PowerPoint PPT Presentation

1 / 40
About This Presentation
Title:

Marco Bellinaso

Description:

Navigation UIs are tedious to implement. Especially if they rely on client-side script ... Specifies appearance of nodes when cursor hovers overhead. NodeStyle ... – PowerPoint PPT presentation

Number of Views:47
Avg rating:3.0/5.0
Slides: 41
Provided by: downloadM
Category:

less

Transcript and Presenter's Notes

Title: Marco Bellinaso


1
Building Dynamic Navigation Systems with Visual
Studio 2005 and ASP.NET 2.0
  • Marco Bellinaso
  • Senior Trainer Consultant
  • Code Architects Srl

2
Agenda
  • Navigation controls
  • TreeView controls
  • Menu controls
  • Site maps
  • XML site maps
  • SiteMapDataSource controls
  • SiteMapPath controls
  • Site map API

3
Site Navigation
  • Navigation UIs are tedious to implement
  • Especially if they rely on client-side script
  • New controls simplify site navigation
  • TreeView and Menu - Navigation UI
  • SiteMapDataSource - XML site maps
  • SiteMapPath - "Bread crumb" controls
  • Public API provides foundation for controls
  • Provider-based for flexibility

4
Site Navigation Schema
Controls
Menu
TreeView
SiteMapPath
SiteMap- DataSource
Site Navigation API
SiteMap
SiteMapNode
SiteMapNode
SiteMapNode
Providers
XmlSiteMapProvider
Other Site Map Providers
Site Maps
Web.sitemap
Other Data Stores
5
TreeView Controls
  • Render hierarchical data as trees
  • Expandable and collapsible branches
  • Nodes are navigable, selectable, or static and
    can include check boxes
  • Content defined by TreeNode objects
  • TreeNodes can be added declaratively,
    programmatically, or through data binding
  • TreeNodes can also be demand-loaded
  • Highly customizable UI

6
Declaring a TreeView
ltaspTreeView RunAt"servergt ltNodesgt
ltaspTreeNode Text"Training" RunAt"server"gt
ltaspTreeNode Text"Programming .NET"
RunAt"server" Navigateurl"Classes.aspx?i
d1" /gt ltaspTreeNode Text"Programming
ASP.NET" RunAt"server"
NavigateUrl"Classes.aspx?id2" /gt
ltaspTreeNode Text"Programming Web Services"
RunAt"server" NavigateUrl"Classes.aspx?i
d3" /gt lt/aspTreeNodegt ltaspTreeNode
Text"Consulting" RunAt"server"
NavigateUrl"Consulting.aspx" /gt
ltaspTreeNode Text"Debugging" RunAt"server"
NavigateUrl"Debugging.aspx" /gt
lt/Nodesgt lt/aspTreeViewgt
7
Key TreeView Properties
Name
Description
CheckedNodes
Indicates which, if any, check boxes are checked
ExpandDepth
Specifies the TreeView's initial expand depth
Nodes
TreeNodeCollection representing tree nodes
SelectedNode
TreeNode representing the node that is currently
selected
ShowCheckBoxes
Specifies which, if any, node types include check
boxes
ShowExpandCollapse
Specifies wehther expand/collapse indicators are
shown
ShowLines
Specifies whether nodes are connected by lines
8
Key TreeView Properties, Cont.
Name
Description
LevelStyles
Specifies appearance of nodes by level
NodeStyle
Specifies default appearance of nodes
RootNodeStyle
Specifies appearance of root nodes
LeafNodeStyle
Specifies appearance of leaf nodes
SelectedNodeStyle
Specifies appearance of selected nodes
HoverNodeStyle
Specifies appearance of nodes when cursor hovers
overhead
ImageUrl properties
Identify expand/collapse indicator images and
others
9
Key TreeNode Properties
Name
Description
Checked
Indicates whether the node's check box is checked
ImageUrl
URL of image to display next to node text
NavigateUrl
URL to navigate to when node is clicked
SelectAction
Action to take when non-navigable node is clicked
Selected
Indicates whether node is currently selected
ShowCheckBox
Specifies whether node includes a check box
Text
Node text
10
Example
ltaspTreeView ShowLines"true" Font-Name"Verdana"
Font-Size"10pt" ... gt ltSelectedNodeStyle
BackColor"Yellow" /gt ltHoverNodeStyle
BackColor"LightBlue" /gt ltNodesgt
ltaspTreeNode Text"Not selectable"
SelectAction"None" RunAt"server"gt
ltaspTreeNode Text"Selectable"
SelectAction"Select" RunAt"server" gt
ltaspTreeNode Text"Click to expand or collapse"
SelectAction"Expand" Runat"server"gt
ltaspTreeNode Text"Click to select and
expand or collapse"
SelectAction"SelectExpand" Runat"server"gt
ltaspTreeNode Text"Check box node"
ShowCheckBox"true"
Runat"server"gt ltaspTreeNode
Text"Click to navigate" NavigateUrl"..."
Runat"server" /gt
lt/aspTreeNodegt lt/aspTreeNodegt
lt/aspTreeNodegt lt/aspTreeNodegt
lt/aspTreeNodegt lt/Nodesgt lt/aspTreeViewgt
11
TreeView Events
Name
Description
CheckChanged
Fired when a check box is checked or unchecked
SelectedNodeChanged
Fired when the selected node changes
TreeNodeCollapsed
Fired when a branch is collapsed
TreeNodeExpanded
Fired when a branch is expanded
TreeNodeDataBound
Fired when a tree node binds to a data source
TreeNodePopulate
Fired when a PopulateOnDemand node needs content
Only fired on server if EnableClientScript"fals
e"
12
Using SelectedNodeChanged
ltaspTreeView ID"Tree" OnSelectedNodeChanged"OnU
pdate" RunAt"server"gt ltNodesgt ...
lt/Nodesgt lt/aspTreeViewgt . . . ltscript
language"C" runat"server"gt void OnUpdate
(Object sender, EventArgs e) // Get the
text of the selected node string text
Tree.SelectedNode.Text ... lt/scriptgt
13
Populating Nodes on Demand
ltaspTreeView OnTreeNodePopulate"OnPopulate"
EnableClientScript"false" RunAt"server"gt
ltNodesgt ltaspTreeNode Text"Populate this
node on demand" PopulateOnDemand"true"
RunAt"server" /gt lt/Nodesgt lt/aspTreeViewgt .
. . ltscript language"C" runat"server"gt void
OnPopulate (Object sender, TreeNodeEventArgs
e) // Called first time the
populate-on-demand node is expanded TreeNode
node new TreeNode ("This node added
dynamically") e.Node.ChildNodes.Add
(node) lt/scriptgt
14
Menu Controls
  • Drop-down/fly-out menus for Web pages
  • Items are navigable or selectable
  • Can be oriented horizontally or vertically
  • Content defined by MenuItem objects
  • MenuItems can be added declaratively,
    programmatically, or through data binding
  • Highly customizable UI

15
Declaring a Menu
ltaspMenu Orientation"Horizontal"
RunAt"server"gt ltItemsgt ltaspMenuItem
Text"Training" RunAt"server"gt
ltaspMenuItem Text"Programming .NET"
RunAt"server" Navigateurl"Classes.aspx?i
d1" /gt ltaspMenuItem Text"Programming
ASP.NET" RunAt"server"
NavigateUrl"Classes.aspx?id2" /gt
ltaspMenuItem Text"Programming Web Services"
RunAt"server" NavigateUrl"Classes.aspx?i
d3" /gt lt/aspMenuItemgt ltaspMenuItem
Text"Consulting" RunAt"server"
NavigateUrl"Consulting.aspx" /gt
ltaspMenuItem Text"Debugging" RunAt"server"
NavigateUrl"Debugging.aspx" /gt
lt/Itemsgt lt/aspMenugt
16
Key Menu Properties
Name
Description
Items
MenuItemCollection representing menu items
ItemWrap
Specifies whether menu item should wrap
Orientation
Specifies whether to orient menu horizontally or
vertically
SelectedItem
MenuItem representing the item that is currently
selected
StaticStyle properties
Specify appearance of static menus
DynamicStyle properties
Specify appearance of dynamic menus
17
Key MenuItem Properties
Name
Description
ImageUrl
URL of image to display next to menu item text
NavigateUrl
URL to navigate to when menu item is clicked
Selected
Indicates whether the item is currently selected
Text
Menu item text (visible to user)
ToolTip
Tooltip text displayed when cursor pauses over
menu item
Value
Menu item value (not visible to user)
18
Menu Events
Name
Description
MenuItemClick
Fired when a menu item is clicked
MenuItemDataBound
Fired when a menu item binds to a data source
19
Using MenuItemClick
ltaspMenu ... OnMenuItemClick"OnClick"
RunAt"server"gt ltItemsgt ...
lt/Itemsgt lt/aspMenugt . . . ltscript
language"C" runat"server"gt void OnClick
(Object sender, MenuEventArgs e) // Get the
text of the selected menu item string text
e.Item.Text ... lt/scriptgt
20
Menu-Driven Navigation
Name Title Microsoft Corporation
21
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
  • Provider-based for flexible data storage

22
XML Site Map
ltsiteMapgt ltsiteMapNode title"Home"
description"" url"default.aspx"gt
ltsiteMapNode title"Training" url"Training.aspx"
description"Training for .NET
developers"gt ltsiteMapNode
title"Programming .NET" url"Classes.aspx?id1"
description"All about the .NET Framework"
/gt ltsiteMapNode title"Programming ASP.NET"
url"Classes.aspx?id2" description"All
about ASP.NET" /gt ltsiteMapNode
title"Programming Web Services"
url"Classes.aspx?id3" description"All
about Web services" /gt lt/siteMapNodegt
ltsiteMapNode title"Consulting"
url"Consulting.aspx" description"Consultin
g for .NET projects" /gt ltsiteMapNode
title"Debugging" url"Debugging.aspx"
description"Help when you need it the most" /gt
lt/siteMapNodegt lt/siteMapgt
23
TreeViews and Site Maps
ltaspSiteMapDataSource ID"SiteMap"
RunAt"server" /gt ltaspTreeView
DataSourceID"SiteMap" RunAt"server" /gt
Web.sitemap
ltsiteMapgt ltsiteMapNode title"Home"
description"" url"default.aspx"gt
ltsiteMapNode title"Training" url"Training.aspx"
description"Training for .NET
developers"gt ltsiteMapNode
title"Programming .NET" url"Classes.aspx?id1"
description"All about the .NET Framework"
/gt ltsiteMapNode title"Programming ASP.NET"
url"Classes.aspx?id2" description"All
about ASP.NET" /gt ltsiteMapNode
title"Programming Web Services"
url"Classes.aspx?id3" description"All
about Web services" /gt lt/siteMapNodegt
ltsiteMapNode title"Consulting"
url"Consulting.aspx" description"Consultin
g for .NET projects" /gt ltsiteMapNode
title"Debugging" url"Debugging.aspx"
description"Help when you need it the most" /gt
lt/siteMapNodegt lt/siteMapgt
24
Menus and Site Maps
ltaspSiteMapDataSource ID"SiteMap"
RunAt"server" /gt ltaspMenu DataSourceID"SiteMap"
RunAt"server" /gt
Web.sitemap
ltsiteMapgt ltsiteMapNode title"Home"
description"" url"default.aspx"gt
ltsiteMapNode title"Training" url"Training.aspx"
description"Training for .NET
developers"gt ltsiteMapNode
title"Programming .NET" url"Classes.aspx?id1"
description"All about the .NET Framework"
/gt ltsiteMapNode title"Programming ASP.NET"
url"Classes.aspx?id2" description"All
about ASP.NET" /gt ltsiteMapNode
title"Programming Web Services"
url"Classes.aspx?id3" description"All
about Web services" /gt lt/siteMapNodegt
ltsiteMapNode title"Consulting"
url"Consulting.aspx" description"Consultin
g for .NET projects" /gt ltsiteMapNode
title"Debugging" url"Debugging.aspx"
description"Help when you need it the most" /gt
lt/siteMapNodegt lt/siteMapgt
25
Changing the File Name
ltconfigurationgt ltsystem.webgt ltsiteMapgt
ltprovidersgt ltremove name"AspNetXmlSiteMa
pProvider" /gt ltadd name"AspNetXmlSiteMapP
rovider" type"System.Web.XmlSiteMapProv
ider, System.Web, ..."
siteMapFile"Acme.sitemap" /gt lt/providersgt
lt/siteMapgt lt/system.webgt lt/configurationgt
26
ltsiteMapNodegt Attributes
Name
Description
description
Description of node
roles
Role or roles for which this node is visible
title
Title of this node
url
URL of this node
Multiple roles can be specified using comma- or
semicolon-delimited lists
27
Security Trimming
Visible to everyone
ltsiteMapgt ltsiteMapNode title"Home"
description"" url"default.aspx"gt
ltsiteMapNode title"Announcements"
url"Announcements.aspx" description"Inform
ation for all employees" /gt ltsiteMapNode
title"Salaries" url"Salaries.aspx"
description"Salary data" roles"Managers,CEOs"
/gt ltsiteMapNodegt lt/siteMapgt
Visible only to Managers and CEOs
28
Enabling Security Trimming
ltconfigurationgt ltsystem.webgt ltsiteMapgt
ltprovidersgt ltremove name"AspNetXmlSiteMa
pProvider" /gt ltadd name"AspNetXmlSiteMapP
rovider" type"System.Web.XmlSiteMapProv
ider, System.Web, ..."
securityTrimmingEnabled"true"
siteMapFile"web.sitemap" /gt lt/providersgt
lt/siteMapgt lt/system.webgt lt/configurationgt
29
SiteMapDataSource Properties
Name
Description
Provider
Provider used to obtain site map data
SiteMapProvider
Name of provider used to obtain site map data
ShowStartingNode
Specifies whether to show the root node
StartFromCurrentNode
Specifies whether starting node should be the
root node (false) or the current node (true).
Default false
StartingNodeOffset
Starting node identified by level (default 0)
StartingNodeUrl
Starting node identified by URL
30
Hiding the Root Site Map Node
ltaspSiteMapDataSource ID"SiteMap"
ShowStartingNode"false" RunAt"server"
/gt ltaspTreeView DataSourceID"SiteMap"
RunAt"server" /gt
Web.sitemap
ltsiteMapgt ltsiteMapNode title"Home"
description"" url"default.aspx"gt
ltsiteMapNode title"Training" url"Training.aspx"
description"Training for .NET
developers"gt ltsiteMapNode
title"Programming .NET" url"Classes.aspx?id1"
description"All about the .NET Framework"
/gt ltsiteMapNode title"Programming ASP.NET"
url"Classes.aspx?id2" description"All
about ASP.NET" /gt ltsiteMapNode
title"Programming Web Services"
url"Classes.aspx?id3" description"All
about Web services" /gt lt/siteMapNodegt
ltsiteMapNode title"Consulting"
url"Consulting.aspx" description"Consultin
g for .NET projects" /gt ltsiteMapNode
title"Debugging" url"Debugging.aspx"
description"Help when you need it the most" /gt
lt/siteMapNodegt lt/siteMapgt
31
SiteMapDataSource
Name Title Microsoft Corporation
32
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
  • Integrates with site map providers to acquire and
    path info

33
Using SiteMapPath
ltaspSiteMapPath RunAt"server" /gt
34
Key SiteMapPath Properties
Name
Description
CurrentNodeStyle
Style used to render the current node
CurrentNodeTemplate
HTML template used to render the current node
NodeStyle
Style used to render non-current nodes
NodeStyleTemplate
HTML template used to render non-current nodes
PathSeparator
Text used for node separators (default "gt")
PathSeparatorStyle
Style used to render node separators
PathSeparatorTemplate
HTML template used to render node separators
35
Stylizing SiteMapPath
ltaspSiteMapPath Font-Name"Verdana"
Font-Size"10pt" RunAt"server"gt
ltCurrentNodeStyle Height"24px"
BackColor"Yellow" Font-Bold"true" /gt
ltNodeStyle Height"24px" /gt ltPathSeparatorTempla
tegt ltItemTemplategt ltaspImage
ImageUrl"/images/arrow.gif" RunAt"server" /gt
lt/ItemTemplategt lt/PathSeparatorTemplategt lt/asp
SiteMapPathgt
36
SiteMapPath
Name Title Microsoft Corporation
37
Site Map Providers
  • Site maps are provider-based
  • Provider interprets site map data and provides it
    to SiteMapDataSource controls
  • Provider also tracks current position and
    provides it to SiteMapPath controls
  • ASP.NET 2.0 ships with one provider
  • XmlSiteMapProvider
  • Use custom providers for other data stores

38
Site Map API
  • System.Web.SiteMap represents site maps
  • RootNode property identifies root node
  • CurrentNode property identifies current node
  • SiteMapNode represents nodes
  • Interrogate properties of node
  • Walk up, down, and sideways in the hierarchy
  • The magic underlying SiteMapPath controls
  • Foundation for building controls of your own

39
Using the Site Map API
// 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 SiteMapNode node SiteMap.CurrentNode St
ringBuilder builder new StringBuilder
(node.Title) while (node.ParentNode ! null)
node node.ParentNode builder.Insert (0,
" gt ") builder.Insert (0, node.Title) L
abel1.Text builder.ToString ()
40
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com