Our recent project at work lately (and the main reason for my previous two months of blog silence) has been upgrading and re-theming our installation of Community Server. I’ve written a few posts in the past on the couple of modules and customizations I’ve done for our current site, and this upgrade is no different. In fact, I’ve had to do more! The most recent one I did just a few minutes ago just happens to be not Community Server-specific at all, but a regular ol’ ASP.NET trick, so I wanted to write about it first. You’ll see more about the Community Server-specific customizations I’ve had to do following this post.
Community Server sites are really just the “Community Server Platform” (which encompasses a whole lotta stuff!), and a customizable theme on top of that platform. Like any well-made site, CS themes are plain ol’ ASPX pages with a mixture of user and server controls. This leaves us with themes that have got somewhere between a dozen and a million pages with the following mark-up:
<CSForum:BreadCrumb runat="server" Tag="Div" />
… but I don’t like what it’s outputting and I want to override some of its behavior. Overriding the control’s behavior is easy enough, of course – you just extend the class and throw in an override here and there and you’re all good. Now we’ve got our new control – Infragistics.CommunityServer.Controls.ForumsBreadCrumb – and the trick is getting this nice shiny control in place. Your first thought might be that we’re up for a massive global search n’ replace, right? Wrong!
I know I kinda ruined the surprise in the title of this post, but for those of you who skipped over that part, forget the global replace – it’s tag mappings to the rescue! Tag mappings allow you to substitute (or map if you want to get technical) one control for another using a simple web.config change! In our case, we’ll do this:
It’s pretty straight-forward – you’re telling ASP.NET that everywhere you’ve used a tag in your markup (tagType) you want to use another type instead (mappedTagType). This makes it really easy to override and/or extend the functionality of a control and use your custom version instead of the original, without changing any of your code!
This tactic can really help you reduce the risk of such a major change, since - I don’t know about you - but my history with global replacements in markup pages have more often than not cost me more problems (and time spent fixing those problems) than if I had just manually made all the replacements to begin with. Next time you’re tempted to do a global replace on a control, take a couple of seconds to think about whether or not this tactic will work for you. It might end up saving you quite a bit of time!
And, as always, happy coding!