Link to home
Start Free TrialLog in
Avatar of Dovberman
DovbermanFlag for United States of America

asked on

How to handle the Treeview OnSelectedNodeChanged event

I am using a Treeview menu based on a sitemap.

There are Anonymous users and 2 roles: Admin and Member

I anyone not logged in is an anonymous user.

I need to restrict anonymous users to certain menu choices.

I need to restrict Member users to certain treeview menu choices.

Admin has no restrictions.

I can test the user and role in the page load event and redirect to default.aspx.

I have heard about the technique of having a Members Only directory but need information about how to use it.

How can I handle the OnSelectedNodeChanged event that fires when a menu option is selected from the Treeview?

The menu references the sitemap. Navigation upon node selection works well.

The following code does not break in the OnSelectedNodeChanged event.

Thanks,

MasterPage.Master.aspx
 
<asp:SiteMapPath ID="SiteMapPath1" runat="server" Width="264px" Font-Size="10pt">
              <PathSeparatorTemplate>
                <asp:Image ID="Image1" ImageUrl="~/Images/arrowright.gif" runat="server" />
              </PathSeparatorTemplate>
              <RootNodeTemplate>
                <b style="font-family: Tahoma; font-size: 12px; font-style: normal">Quick Menu</b>
                <br /><br />
              </RootNodeTemplate>
              
              <CurrentNodeTemplate>
                <%# Eval("title") %> <br /><b style="font-family: Tahoma; font-size: 10px"></b><br />&nbsp;<%# Eval("description") %><br />
              </CurrentNodeTemplate>
            </asp:SiteMapPath>
            <br /><br />
<asp:TreeView ID="tvwMenu" runat="server"
     DataSourceID="SiteMapDataSource1" ImageSet="Faq" NodeIndent="0" Width="158px" 
     SelectedNodeStyle-VerticalPadding="0"
     OnSelectedNodeChanged="tvwMenu_SelectionChanged" >  
                
     <ParentNodeStyle Font-Bold="False" />
     <HoverNodeStyle Font-Underline="True" ForeColor="Purple" />
     <SelectedNodeStyle Font-Underline="True" ForeColor="Green" />
     <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="DarkBlue" HorizontalPadding="5px"
     NodeSpacing="0px" VerticalPadding="0px"/>
</asp:TreeView>
 
MasterPage.Master.cs
 
public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
  
    }
 
    protected void tvwMenu_SelectionChanged(object sender, EventArgs e)
    {
        //Break point here. Execution does not pause.
	string strSelectedNode = tvwMenu.SelectedNode.Value;
    }
 
 
}

Open in new window

Avatar of tetorvik
tetorvik
Flag of Finland image

About the OnSelectedNodeChanged  event:
If the TreeNode's NavigateURL is not empty or null, when click on the TreeNode, the current page will be redirected to the selectedNode's NavigateURL directly without postback, so the TreeView's OnSelectedNodeChanged  event will not be fired.

restricting navigation see the link (especially "Site Navigation Security" section)
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/navigation/sitenavapi.aspx
Avatar of Dovberman

ASKER

Does this mean that I do not need the OnSelectedNodeChanged event to restrict users depending on their role ? Instead, I can use the location tag ?

<location path="SectionOne.aspx">
    <system.web>
      <authorization>
        <allow users="SectionOne" roles="Administrators"  />
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>
  <location path="SectionOne">
    <system.web>
      <authorization>
        <allow users="SectionOne" roles="Administrators"/>
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>
ASKER CERTIFIED SOLUTION
Avatar of tetorvik
tetorvik
Flag of Finland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree that users should see only those options that are available to them. I wish I could dim the unauthorized treeview nodes.

I will look at the custom site map provider you referenced

Thanks,