Dave Burke : Freelance .NET Web Developer specializing in Online Communities

CS Nuglet: Tab Selection - The Unabridged Version

An issue that always arises when creating a Content Page or adding custom Community Server features (like my iTunes Library or Blogroll, for example), is how do we get the Selected Menu Tab to get focus when we are on that page.  We want this, in other words.



First, to create a new navigation tab we add it to the SiteUrls.config in the < Navigation /> area, like so:

< link name="myArticle" navigateUrl="/content/MySweetArticle.aspx" text="My Article" roles="Everyone"  / >

Now the trick is to send that link name back to the SelectedNavigation Class on the page that loads the new Content Page or feature.  We do that by loading the SelectedNavigation control with the "Selected" property designating the name of the link in our SiteUrls.config file.

< CS:SelectedNavigation Selected = "myArticle" runat="Server" ID="Selectednavigation1"/ >

If we're adding a new Content Page, we can load the control in  /Themes/default/Skings/Skin-ContentArticle.ascx. 

But what if we have two Content Pages, or we add a new feature, like my goofy iTunes Library, for instance.  Well, in the case of my  iTunes Library, I made new LayoutTemplate.ascx and BlogMaster.ascx templates which is where I passed the "Selected" property to the SelectedNavigation class.

If you want to be a dirty boy or girl, you could always hack the SelectedNavigation class itself and doing a URL check (as I did with my blogroll page.)  I'm not proud of it, but here it is.

protected override void OnLoad(EventArgs e)
{
    if (Page.Request.Url.ToString().IndexOf("linklist.aspx") > 0)  // DBVT Added
        Context.Items["SelectedNavigation"] = "blogroll";
    else
        Context.Items["SelectedNavigation"] = this.Selected;
    base.OnLoad (e);
}


That should do it.  Everything we need to make those tab buttons go up and down when they're supposed to.

[tags: Community Server, CSNavigation]

Comments (6) | Post RSS RSS comment feed

Posted on 6/1/2006 7:25:00 AM by Dave Burke
Categories: Community Server
Tags: no tags for this post

Related posts

Comments (6) -

6/23/2006 6:33:24 AM Permalink

I couldn't get it to work using /Themes/default/Skings/Skin-ContentArticle.ascx.  
WHen I added the SelectedNavigation control to the utility/ShowContent.aspx, it worked fine.
Did i do some thing wrong?

Aubrey |

6/23/2006 7:20:29 AM Permalink

Hey, Aubrey!  It should have worked in the ContentArticle control if you indeed added a new content page, but you're absolutely right, placing it in the ShowContent.aspx file would work, too.  Good work on finding an alternate solution.

daveburke |

8/14/2006 1:08:04 PM Permalink

I am not finding anything in the CS administrator for adding content pages. Is this something that I can do in CS or do I have to make a new acsx file manually?
Thanks,
Michael

Michael S. Scherotter |

8/14/2006 1:44:12 PM Permalink

Michael,

Here's the article from Dan Bartels that pretty much started it all. Smile  Hopefully this will help.

blog.danbartels.com/archive/2006/04/25/2334.aspx

daveburke |

12/9/2006 12:52:01 PM Permalink

Exactly what I was looking for - cheers.

Rob Holmes |

12/19/2006 7:53:54 AM Permalink

Thanks for this, Dave. I needed to know this today and it came in handy.

Sean Winstead |


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke