Friday, June 26, 2009

DotNetNuke - Alternative for using getTabByName or getTab

Hey.
many time in dotnetnuke module development, you need to redirect an existing request to another page. I see most of the users use TabController.getTabByName method to get TabInfo object, And then use its TabId property to navigate to that page using DotNetNuke.Common.Globals.NavigateUrl() method.

Getting entire TabInfo object from database for only getting TabId doesn't seems correct in terms of performance. I see many developers who add intelligence to this by adding entire set of tabs for a portal in HashTable and uses TabId as key and TabName as value. We can add some static methods to get the TabId by name or get TabName by Id.

This approach seems to be perfect, but it still needs memory, if we store it in session state. We always have alternative to store the HashTable into Cache also. That will be more proper way to store data. Adding more tricky work is to add SqlCacheDependency into that. So that when set of Tabs changes, it automatically loads the new set of Tabs.

But this is way too intelligent technique. When you don't need the TabIds too many time in your development or you need to redirect to a specific Tab many times, you should use SiteUrl.config. Let's discuss when its useful.

For example you have a module that shows a message about an offer's page in your site, and you are showing the module in many pages. Now when a user clicks on it, we are sure that we need to redirect user to TabId=100. But you cannot place it hard code, Because you are not sure if the page is having a same id on when it will be deployed.

So the simple work around is to create an entry in the siteUrl.Config file for that TabId. Let's say we create an entry which looks for Offers.aspx and redirect it to Default.aspx?tabid=100. And that's it. It will never go to database to find TabId of the offer.aspx. and the code will get rid of the TabInfo loading from database of maintaining the set of tabs in memory for faster access.

I hope I understand the problem well and make you able to give a right trick. Tell me what you think about it?

No comments:

Post a Comment

Please add your valuable comments about this post if it helped you. Thanks

Popular Posts