1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Custom navigation drop down control

Custom navigation drop down control

7 posts, 0 answered
  1. License Developer
    License Developer avatar
    31 posts
    Registered:
    18 Jun 2008
    20 Jun 2008
    Link to this post
    This forum has been so great at providing useful information I thought I'd try humbly asking yet another question.

    I've read the dev manual, watched the videos, and experimented with CmsSiteMapNode but would very much appreciate it if anyone here could help with this question.

    The goal is to create a user control that is a drop down list that is aware of the user's current contextual placement in the site, create a drop down of nodes, and redirect users who select the items in the drop down to an appropriate page.

    Our site(s) taxonomy in Sitefinity is as such:

    root
      - Subsite for Subject1 (page group)
           -- July 2008 (page group)
                --- Subject1 June 2008  home - go here when S1 July 08 is selected
                --- (page group a)
                --- (page group b)

           -- August 2008 (page group)
                --- Subject1 August 2008  home go here when S1 August 08 is selected
                --- (page group a)
                --- (page group b)
    ---------------------------------------------
      - Subsite for Subject 2 (page group)
           -- July 2008 (page group)
                --- Subject2 July 2008  home go here when S2 July 08 is selected
                --- (page group a)
                --- (page group b)

           -- August 2008 (page group)
                --- Subject2 August 2008  home go here when S2 August 08 is selected
                --- (page group a)
                --- (page group b)

    In the above example what we need help with is creating a drop down list that would show:
    July 2008
    August 2008

    and redirect a user to the appropriate "home" page for the group selected based off of context. If the user is in Subsite for Subject 2 and selects July 2008 they should go to the "home" page for July 2008 under Subject 2.

    Any help would be greatly appreciated. I'm used to working in sprints of weeks and am doing them in days now.

    Thanks!!

  2. License Developer
    License Developer avatar
    31 posts
    Registered:
    18 Jun 2008
    22 Jun 2008
    Link to this post
    I think I have this almost finished. My control is walking up and down the sitemap, filling the dropdown list with the correct titles and redirect URLs, but I have a couple of questions.

    In sitefinity is the best way to redirect on my SelectedIndexChanged by using Response.Redirect?

    My drop down list control is not going back to the server when I change the selected item, any ideas why it's just acting like a plain html drop down?

    Lastly I haven't figured out a good way to debug. My process feels very outdated. I make some changes to my .cs, include response.write statements so I can see what's going on,  reupload my control, edit web.config so my control folder isn't a mess and then test the control.

    Can I just upload a custom control once, then edit it where sitefinity saves it and debug from there?
  3. Meister
    Meister avatar
    262 posts
    Registered:
    09 Nov 2007
    22 Jun 2008
    Link to this post
    Hi Bret

    This is something i was looking for
    I dont suppose you fancy sharing this control with the community once done?

    Good luck!
    Thanks
  4. License Developer
    License Developer avatar
    31 posts
    Registered:
    18 Jun 2008
    22 Jun 2008
    Link to this post
    I'll be happy to share it with you.

    I think that this forum is great and one thing that I would like to do is to encourage people to share "cool snippits" of code so we could have a resource for community code development. There's thousands of sites that I can google if I'm looking to do something with MOSS or RedDot or whatever but this forum looks like it's "it" when it comes to sitefinity so I'm all for sharing code and encouraging others to do the same.

    I should have something that's worth uploading later tonight.
  5. Meister
    Meister avatar
    262 posts
    Registered:
    09 Nov 2007
    23 Jun 2008
    Link to this post
    thanks Bret thats great
    i'm looking forward to it

    Cheers
  6. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    23 Jun 2008
    Link to this post
    Hi,

    Someone could post the sample code for this post. Regards
  7. License Developer
    License Developer avatar
    31 posts
    Registered:
    18 Jun 2008
    25 Jun 2008
    Link to this post
    Hi,

    It was done in a rush so there are some things that I would like to clean up.

    IssueDropDownNav.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="IssueDropdownNav.ascx.cs" Inherits="CustomControls_IssueDropdownNav" %> 
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" /> 
    <asp:DropDownList ID="ddlMarketscapeIssues" runat="server"    
        onselectedindexchanged="ddlMarketscapeIssues_SelectedIndexChanged"  
        CssClass="dropDownIssueNav" AutoPostBack="True"
    </asp:DropDownList> 

    IssueDropDownNav.ascx.cs

    A few rules.
    1. My top node for each issue has "_Issue_Top_" hard coded into the file name.
    My assumption is that issues may some day be higher or lower in the structure. I'm not sure but I think that a custom meta property may be able to be added into the page, that would be more elegant to check for.

    2. This control needs to get it's geographic location set. This is also a "where should I start from" thing. I think that having it in place now will also allow us to do other things in the future. (Make a control that displays all locations so we can switch between?). This is done by the "public string GeographicLocation". When the control is dragged onto a page and you click "edit" there will now be a place to type "Boston" for example.

    Lastly, I've tested this but it's not been QAd. It's code as is. If I have time I'll answer questions but no promises right now :)

    using System; 
    using System.Collections; 
    using System.Configuration; 
    using System.Data; 
    using System.Linq; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.HtmlControls; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using System.Xml.Linq; 
     
    using Telerik.Cms; 
    using Telerik.Cms.Web; 
     
    public partial class CustomControls_IssueDropdownNav : System.Web.UI.UserControl 
        private string geographicLocation; 
     
        public string GeographicLocation 
        { 
            get 
            { 
                return this.geographicLocation; 
            } 
            set 
            { 
                this.geographicLocation = value.Trim().ToUpper(); 
            } 
        } 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!Page.IsPostBack)  
            { 
                ddlMarketscapeIssues.Items.Clear();  
                //If the CMS user has not set the geographic location on this page show an error in the control area 
                //PROBLEM - when this message is displayed I can no longer see the trash/edit sitefinity icons 
                if (this.geographicLocation == null
                { 
                    throw new InvalidOperationException("<font color=red> Error: Geographic Location is not set.</font>"); 
     
                } 
     
                string sIssueHomeTitle = ""
                string sIssueHomeUrl = ""
                string sCurrentIssueUrl = ""// catch the issue that should be *selected* in the drop down. 
     
                //starting current node in the page where the user is 
                CmsSiteMapNode currentNode = SiteMap.CurrentNode as CmsSiteMapNode; 
                if (currentNode == null//probably editing the template 
                { 
                    return;//throwing the exception makes the page not visible in preview mode when editing the template 
                    //makes the page break in edit mode: 
                    //throw new InvalidOperationException("<font color=red> Error: No sitemap nodes available.</font>"); 
                } 
                // verify that the currentNode has a parent 
                if (currentNode.ParentNode == null
                { 
                    throw new InvalidOperationException("<font color=red> Error: This page has no parents.</font>"); 
                } 
                else 
                { 
                    // Go UP until you find the geographic location set in page properties 
                    while (currentNode.Title.Trim().ToUpper() != this.geographicLocation) //we stop when we get up to the geo location 
                    { 
     
                        if (currentNode.ParentNode == null
                        { 
                            //No geographic location found up the tree 
                            throw new InvalidOperationException("<font color=red> Error: Geographic Location is not found.</font>"); 
                        } 
                        currentNode = currentNode.ParentNode as CmsSiteMapNode; 
                        //test if this is the "issue" node  
                        if (currentNode.Url.Contains("_Issue_Top_")) //identifying the "Issue top" by hard coding it into the file name 
                        { 
                            //we're at the top of the current issue 
                            sCurrentIssueUrl = currentNode.Url; 
                        } 
     
                    }// end while 
     
                    //Now go down to find this location's issues.  
                    //Make sure to select the issue the user is looking at now 
                    int issueIndex = 0; 
                    foreach (CmsSiteMapNode issueNode in currentNode.ChildNodes) //iterate through issues - "AUGUST 2008", "SEPTEMBER 2008" etc 
                    { 
                        if (issueNode.HasChildNodes)//looking for page groups 
                        { 
                            //resetting values 
                            sIssueHomeTitle = ""
                            sIssueHomeUrl = ""
     
                            //setting Issue Title - title is the name of the page group 
                            sIssueHomeTitle = issueNode.Title; 
     
                            sIssueHomeUrl = issueNode.Url; //Defaults to the top page in the sitemap of this node - in my case it needs to be the "Home" page 
                            ddlMarketscapeIssues.Items.Add(new ListItem(sIssueHomeTitle, sIssueHomeUrl)); 
     
                            if (sCurrentIssueUrl == sIssueHomeUrl) 
                            { 
                                ddlMarketscapeIssues.SelectedIndex = issueIndex; 
                            } 
                            issueIndex++; 
                        } 
                    }//end foreach issue loop 
     
                }// end if for starting node parent check 
            } 
        } 
        protected void ddlMarketscapeIssues_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            Response.Redirect(ddlMarketscapeIssues.SelectedValue.ToString()); 
        } 
     

    So in my instance we walk up the parents, find the location that contains the issues, then build out a drop down of the issues. The links are to the issue  page groups and my top most page in my site map for each issue is my "Home" page for that issue.  Sitefinity's default behavior when you make a link to a group is to navigate to the top most page in the site map of the page group.

    Good luck!




Register for webinar
7 posts, 0 answered