I am using asp:Menu to show menubar. The menu control uses sitemap as datasource. Now I want to delete some child nodes from sitemap node based on permission. I tried to manipulate Mennuitems but unable to delete that child node.
This is code to my menu control
<td class="TRMenu" valign="middle" align="left">
<asp:Menu ID="menu" runat="server" CssClass="menu" EnableViewState="False" Orientation="Horizontal"
DataSourceID="newSiteMap">
</asp:Menu>
<asp:SiteMapDataSource ID="newSiteMap" runat="server" ShowStartingNode="False" StartingNodeUrl="~/_PL/SPONSOR/Default.aspx" />
</td>
This is the code to my sitemap
<siteMapNode url="~/_PL/SPONSOR/Default.aspx" title="SPONSOR" description="SPONSOR">
<siteMapNode url="~/_PL/SPONSOR/Home.aspx" title="HOME" description="HOME" />
<siteMapNode url="~/_PL/SPONSOR/Default.aspx?0" title="Dash Board" description="Dash Board" />
<siteMapNode url="~/_PL/SPONSOR/SiteViewAll.aspx" title="Site Info." description="Site Information" id="Site">
<siteMapNode url="~/_PL/SPONSOR/Site.aspx" title="Add/Update Site Info." description="Add/Update Site Information" id="Add"/>
<siteMapNode url="~/_PL/SPONSOR/SiteViewAll.aspx?0" title="View Site Info." description="View Site Information" />
</siteMapNode>
<siteMapNode url="~/_PL/SPONSOR/UserViewAll.aspx" title="User Info." description="User Info" >
<siteMapNode url="~/_PL/SPONSOR/User.aspx?New" title="Add/Update User Info." description="Add/Update User Information" />
<siteMapNode url="~/_PL/SPONSOR/UserViewHirerchical.aspx" title="View Hirerchical User" description="View Hirerchical User Information" />
<siteMapNode url="~/_PL/SPONSOR/UserViewAll.aspx?0" title="View User Info." description="View User Information" />
</siteMapNode>
<!--<siteMapNode url="~/_PL/SPONSOR/CRFProtocol.aspx" title="CRF Protocol" description="CRF Protocol" />-->
<siteMapNode url="~/_PL/SPONSOR/eCRFDownload.aspx" title="CRF Download Forms" description="CRF Download Forms" />
<siteMapNode url="~/_PL/SPONSOR/LogSheet.aspx" title="Log Sheet" description="Log Sheet" />
<siteMapNode url="~/Default.aspx?logout=SPONSOR" title="Logout" description="Logout" />
</siteMapNode>
I want to remove below node based on the permission
<siteMapNode url="~/_PL/SPONSOR/Site.aspx" title="Add/Update Site Info." description="Add/Update Site Information" id="Add"/>
I have tried following method.
protected void Page_Unload(object sender, EventArgs e)
{
foreach (MenuItem Item in menu.Items)
{
if (Item.Text.Contains("Site"))
{
string str = Item.ChildItems[0].Text;
Item.ChildItems.RemoveAt(0);
}
}
}
I tried this in page load and prerender methods also but still the node is there when the page is loaded.
How can I remove it.?
I think right way to implement it is in the DataBound-Event of the menu-control:
Page.Unload-Event finds Items but seems not to be able to influence state of controls any more (probably because it is meant for other things).