Updated April 7, 2023
Introduction to Navigation Control in ASP.NET
Navigation control in ASP.NET manages the data passing between ASPX pages. Web applications are having multiple pages interconnected with each other. So proper navigation system must be there which can help the end user to successfully work through an application. There are standard methods are available in ASP.NET 1.x that offers well defined navigation system for the web application. Only the method which is present for building navigation within web application is to fill the pages with hyperlinks. The drawbacks of hyperlink are when you move pages around or change pages names.
When the site grows and new pages are added and at that time it is very difficult for the developer to manage all links in the application. ASP.NET 2.0 and above eliminate problems of links with a built in site navigation features. It provides consistent way for the user to navigate the website. It enables defining all the links at central location file as xml file and display those links in list or navigation menus in each required page using navigation controls.
Different Navigation Controls in ASP.NET
There are three navigation control in ASP.NET:
- SiteMapPath
- Menu Control
- TreeView
1. SiteMapPath Control
Site maps are XML files which are mainly used to describe the logical structure of the web application. It defines the layout of all pages in web application and how they relate to each other. Whenever you want you can add or remove pages to your site map there by managing navigation of website efficiently. Site map files are defined with .sitemap extension. <sitemap> element is the root node of the sitemap file.
It has three attributes:
- Title: It provides textual description of the link.
- URL: It provides the location of the valid physical file.
- Description: It is used for tooltip of the link.
SiteMapPath control displays the navigation path of the current page. The path acts as click able links to previous page. The sitemap path control uses the web. This control creates the navigation mechanism which is linear path defining where the user is currently located in navigation arrangement. It helps end user to know his location in relation to the rest of the site.
Properties of SiteMapPath Control:
- PathSeparator: This property is to get or set the out separator text.
- NodeStyle: This property is used to set the style of all nodes that will be displayed.
- RootNodeStyle: This property is used to set the style on the absolute root node.
- PathDirection: This property is used to set the direction of the links generated in the output.
- CurrentNodeStyle: This property is used to set the style on node that represent the current page.
- ShowToolTips: This property is used to set the tooltip for the control. Default value is true.
- PathSeparatorStyle: This property ja used to set the style of path separator.
2. Menu Control
Menu is an another navigation control in ASP.NET which is used to display menu in web page. This control is used in combination with SiteMapDataSource control for navigating the web Site. It displays two types of menu static menu and dynamic menu. Static menu is always displayed in menu Control, by default only menu items at the root levels are displayed. Dynamic menu is displayed only when the use moves the mouse pointer over the parent menu that contains a dynamic sub menu.
Properties of Menu Control:
- DataSourceID: This property is used to specify the data source to be used using sitemap file as data source.
- CssClass: This property is used to specify the CSS class attribute for the control.
- ImgeUrl: This property is used to specify the image that appear next to the menu item.
- Orientation: This property is used to specify the alignment of menu control. It can be horizontal or vertical.
- Tooltip: This property is used to specify the tooltip of the menu item when you mouse over.
- Text: This property is used to specify the text to display in the menu.
- NavigateUrl: This property is used to specify the target location to send the user when menu item is clicked.
- Target: This property is used to specify the target page location. It can be in new window or same window.
- Value: This property is used to specify the unique id to use in server side events.
3. TreeView Control
TreeView is an another navigation control used in ASP.NET to display the data in hierarchical list manner. When TreeView is displayed for the first time, it displays all of its nodes. User can control it by setting the property called ExpandDepth.
Properties of TreeView Control:
- DataSourceID: This property is used to specify the data source to be used using sitemap file s data source.
- ShowLines: This property is used to specify the lines to connect the individual item in the tree.
- CssClass: This property is used to specify the CSS class attribute for the control.
- ExpandDepth: This property is used to specify the level at which items in the tree are expanded.
Conclusion
Here we have seen three navigation control that are used in ASP.NET to navigate the web page or data. Based on the requirements, we can make a use of these control with appropriate properties.
Recommended Articles
This is a guide to Navigation Control in ASP.NET. Here we discuss the introduction and different navigation controls in ASP.NET. You may also have a look at the following articles to learn more –