Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to handle the Treeview OnSelectedNodeChanged event

Posted on 2009-05-19
4
Medium Priority
?
1,033 Views
Last Modified: 2012-05-07
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

0
Comment
Question by:Dovberman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 9

Expert Comment

by:tetorvik
ID: 24420457
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
0
 

Author Comment

by:Dovberman
ID: 24421037
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>
0
 
LVL 9

Accepted Solution

by:
tetorvik earned 2000 total points
ID: 24423972
Yes thats the idea and alternatively/additionally you may use sitemap roles property like one of the samples in the link I provided.

Additionaly by setting location tags it also prevents users from navigation restricted pages even when they try accessing a page by typing direct URLs.

In general I think it doesn't make sense to show a navigation menu to user she/he is not allowed to access. If the build-in ASP.NET sitemap provider is still not what you're looking for and you need perhaps some additional logic prior to showing a treeview node, you may consider creating your own custom sitemap provider (http://msdn.microsoft.com/en-us/library/aa479033.aspx)
0
 

Author Comment

by:Dovberman
ID: 24424715
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,
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question