ASP. NET site navigation (1)

Source: Internet
Author: User

In the past few days, I found my predecessors in the garden about ASP. NET site navigation. I found it for a long time, but it was quite rewarding! However, I want to extract my own knowledge about ASP. NET site navigation controls for later use:

You can use the ASP. Net site navigation function to provide users with consistent methods for navigation sites. As the site content increases and you move webpages back and forth on the site, it may be difficult to manage all links. ASP.. Net Site Navigation allows you to store links pointing to all pages in a central location and present these links in the list, you can also use a specific web server control to display navigation menus on each page.

To create a consistent and easy-to-manage navigation solution for a site, you can use ASP. NET site navigation. ASP. NET site navigation provides the following functions:

    • Site MapYou can use a site map to describe the logical structure of a site. You can manage page navigation by modifying the site map (instead of modifying the hyperlinks of all webpages) when adding or removing pages.

    • ASP. NET controlsYou can use the ASP. Net Control to display navigation menus on a webpage. The navigation menu is based on the site map.

    • Programming controlsYou canCodeYou can use ASP. Net site navigation to create custom navigation controls or modify the positions of information displayed in the navigation menu.

    • Access rulesYou can configure access rules to display or hide links in the navigation menu.

    • Custom Site MapProgram You can create a custom site map provider to use your site map backend (such as a database that stores link information) and insert the provider to the ASP. NET site navigation system.

How site navigation works

You can use ASP. Net site navigation to describe the site layout in a hierarchical structure. For example, a site in a virtual online computer store has eight pages. The layout is as follows.

Home
Products
Hardware
Software
Services
Training
Consulting
Support

To use site navigation, first create a site map or site representation. You can use an XML file to describe the hierarchy of the site, but you can also use other methods. For more information and examples, see ASP. NET site map.

After creating a site map, you can use the site navigation control to display the navigation structure on the ASP. NET page. For examples, see How to: add a simple site navigation.

Site Map Loading Process

The default ASP. Net Site Map provider loads site map data as an XML document and caches it as static data when the application starts. Large Site Map Files may occupy a large amount of memory and CPU resources during loading. The ASP. Net site navigation function keeps the navigation data up-to-date based on file notifications. When you change the site map file, ASP. NET reloads the site map data. Make sure that the configuration of all virus scanning software does not modify the site map file. For more information, see secure ASP. NET site navigation.

Site Navigation Control

Creating a site map that reflects the site structure is only part of the ASP. NET site navigation system. The other part of the navigation system is to display the navigation structure in the ASP. NET webpage, so that users can easily move in the site. By using the following ASP. NET site navigation controls, you can easily create navigation information on the page:

    • This control shows the navigation path (also known as the breadcrumb or eyebrow link) to show the location of the current page to the user, and shows the path of the home page returned in the form of a link. This control provides many options for customizing the appearance of a link.

    • This control displays a tree structure or menu that allows users to traverse different pages on the site. Click a node that contains a subnode to expand or collapse it.

    • This control displays an expanded menu that allows you to traverse different pages on the site. When you hover the cursor over the menu, the nodes that contain subnodes are displayed.

In the preceding example Add the control to the training page of the online computer store, The control displays the following content, in which "home" and "services" are displayed as hyperlinks:

Home Page>Service> Training

You can use You do not need to write code or explicitly bind data. This control automatically reads and presents site map information. However, if needed, you can also use custom code Control. For examples, see How to: programmatically modify the site map nodes in the memory.

Controls enable users to navigate back from the current page to a page with a higher level of site hierarchy. However, The control does not allow you to navigate from the current page to other deeper pages in the hierarchy. In a newsgroup or message board application, when users want to view what they are browsingArticleYou can use Control.

Pass Or You can open a node and navigate to a specific page. These controls do not look like Controls to directly read site maps. Instead, you need to add a site map that can be read on the page Control. Then Or Control bound Control to display the site map on this page. The control displays the following similar content:

-Home

-Services

+ Training

Note:

Display on all pages of the site , Or You can create a master page and add the controls to the page. For more information, see ASP. NET master page overview.

Site Navigation API

With the navigation control, you can add site navigation on the page by writing very little code or even without Code. However, you can also process site navigation programmatically.When a web application is running, ASP. NET discloses Object. All members of an object are static members. While Object exposed A collection of objects that contain the attributes of each node in the map. (In use Control, the control uses And The object automatically presents the corresponding link.

SitemapnodeObject indicates a website page in the site map structure.SitemapnodeObjects are loaded by the static sitemap class using one or more site map providers at runtime to load site map data from the permanent storage area to the memory.SitemapnodeObjects are packaged by the sitemapnodeitem class for use by web server controls (such as sitemappath controls.

SitemapnodeThe class includes several attributes used to describe a single page (including a page) of a website, such as the URL, title, and description attributes. net is used by the xmlsitemapprovider class of the Site Map provider by default. This class uses this attribute as the search key for the internal set. The provider uses this search key to track nodes.SitemapnodeClass supports a basic key attribute, which is used by the site map provider to track nodes. In addition, URL attributes are used by the navigation control to display page hyperlinks in the navigation structure. The title attribute isSitemapnodeIs usually the same as the HTML title of the web form, and the navigation control is used to present simple labels. Finally, attach the attributes attribute A collection can be used by some site map providers.SitemapnodeObject, butSitemapnodeAdditional attributes not provided in the base class.

You can use , And Object to traverse the map structure of the site, or create a custom control to display the map data of the site. You cannot write to a site map, but you can modify the site map node in the instance of the object. For more information, see How to: programmatically modify site map nodes in memory or programmatically enumerate site map nodes.

You need to fill in the treenode data

The static definition of the data structure is sometimes not feasible, or the data may depend on the information collected during the runtime. To dynamically display data, Controls Support Dynamic node filling. Set When the control is configured to be filled, the control triggers an event when the user expands the node. The event handler retrieves the corresponding data and fills it with the node you clicked. To fill in data Object. Set propertyTrueAnd create Event Handlers Object.

Client Treeview node Filling

In the browser function configuration file Set propertyTrueAll browsers support filling of client nodes.

With client node filling, You can call Event to fill the node, without completely sending back to the server. For more information about filling client nodes, see .

Enable client script

By default, in the up-level browser, The expand-collapse function of nodes on the control is executed using client scripts. Because the control does not need to be sent back to the server to display the new configuration, you can use the client script to improve the rendering efficiency.

Note:

If the client script in the browser is disabled or the browser does not support the client script The control is restored to the low-level mode and sent back to the server every time the user clicks a node.

Treeview sending back

By default, unless the browser does not support client scripts or Property is setFalseOtherwise The control is displayed on the client. If Property is setTrueThe browser supports client scripts. The control retrieves data from the server without sending the whole page back.

When When the control is in the selection mode, each time the user clicks the node, it will be sent back to the server and Event.

Generally, you should When the control is in the selection mode or the node is being dynamically filled, the event is returned. The reason is: Or The property has been setTrue.

Use the Treeview control with the updatepanel Control

The control is used to update the selected area of the page by sending an update request, instead of updating the entire page. You can Used in the control Control, but has the following restrictions:

  • callback must be associated with asynchronous sending back. Otherwise, callback event verification will fail. In attribute is set to true , callback is enabled. You can use either of the following methods to ensure that callback controls work:

      • If the control is not in the control disable callback on the control. Therefore attribute is set to false .

      • programmatically refresh all the controls that register callback during asynchronous sending back. For example place the control in in the control. the control does not have to be located in refresh the control.

  • Styles must be applied by referencing Cascading Style Sheets (CSS) classes. For exampleProperty-cssclass(Attribute refers to property) attribute to set the style, instead of usingAttribute-subattribute(Property) attribute settings Property ). Similarly UseCssclassAttribute ).

  • The property must beTrue(Default ). In addition, if If callback is enabled for the control, it cannot be changed between asynchronous sending and receiving. Attribute.

Usage For more information, see updatepanel control overview and partial page display overview.

 

Relationship between site navigation Components

The following demonstrates the relationship between various ASP. NET site navigation components.

Copied from msdn

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.