Under Asp.net 2.0, the menu is dynamically controlled based on permissions and navigation information is dynamically configured.

Source: Internet
Author: User

Generally, the management system usually needs to use the permission management menu (whether to display, whether to enable), and the navigation tree control Treeview to form a flexible navigation control solution.

Masterpage is a good idea. You can place both the menu control and the Treeview control in it and provide corresponding data sources. If the menu does not change frequently (normally), you can make the menu and its sub-menus static, and the Treeview content is dynamically loaded according to the menu items.

Interface:

Code:

Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;

Public partial class masterpageperson: system. Web. UI. masterpage
{
Protected void page_load (Object sender, eventargs E)
{
// Permission Control
If (session ["previlege"]. tostring () = "person ")
{
Menu1.enabled = false;
Menu2.visible = false;
Smsresultcheck. provider = system. Web. sitemap. Providers ["smpresultcheck"]; // menu3
}
Else
{
Menu1.enabled = true;
Menu2.visible = true;
Smsresultcheck. provider = system. Web. sitemap. Providers ["smpresultcheck"]; // menu3
}

// Configure the navigation tree content
If (session ["treevprovider"]! = NULL)
This. sitemapdatasource1.provider = system. Web. sitemap. Providers [session ["treevprovider"]. tostring ()];
Else
Smsresultcheck. provider = system. Web. sitemap. Providers ["smpresultcheck"];
}
Protected void menu1_menuitemclick (Object sender, menueventargs E)
{
Session ["treevprovider"] = "codemaintain ";
This. sitemapdatasource1.provider = system. Web. sitemap. Providers [session ["treevprovider"]. tostring ()];
}
Protected void menu2_menuitemclick (Object sender, menueventargs E)
{
String M = menu2.selecteditem. text;
If (M. Equals ("fund management "))
{
Session ["treevprovider"] = "projectprovider ";
This. sitemapdatasource1.provider = system. Web. sitemap. Providers [session ["treevprovider"]. tostring ()];
}

}
Protected void menu3_menuitemclick (Object sender, menueventargs E)
{
String M = menu3.selecteditem. text;
If (M. Equals ("department review "))
{
Session ["treevprovider"] = "smpresultcheckdepartment ";
This. sitemapdatasource1.provider = system. Web. sitemap. Providers [session ["treevprovider"]. tostring ()];
}
}
}
Run:

 

Of course, you need to configure web. config.

<Sitemap enabled = "true">
<Providers>
<Add name = "codemaintain" Description = "sitemap provider that reads in. sitemap files. "type =" system. web. xmlsitemapprovider, system. web, version = 2.0.3600.0, culture = neutral, publickeytoken = b03f5f7f11d50a3a "sitemapfile =" codemaintain. sitemap "/>
<Add name = "projectfee" Description = "sitemap provider that reads in. sitemap files. "type =" system. web. xmlsitemapprovider, system. web, version = 2.0.3600.0, culture = neutral, publickeytoken = b03f5f7f11d50a3a "sitemapfile =" projectworkflow. sitemap "/>
<Add name = "smpresultcheck" Description = "sitemap provider that reads in. sitemap files. "type =" system. web. xmlsitemapprovider, system. web, version = 2.0.3600.0, culture = neutral, publickeytoken = b03f5f7f11d50a3a "sitemapfile =" resultcheck. sitemap "/>
<Add name = "smpresultcheckdepartment" Description = "sitemap provider that reads in. sitemap files. "type =" system. web. xmlsitemapprovider, system. web, version = 2.0.3600.0, culture = neutral, publickeytoken = b03f5f7f11d50a3a "sitemapfile = "~ /Resultcheck/departmentcheck. sitemap "/>
</Providers>
</Sitemap>

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.