The Mighty Blog

Jun25

Written by:Will
6/25/2007  RssIcon

In DotNetNuke, you generally are always working with the tab (page) that you are currently on whether it be at the module level or not. However, on occassion, you might need to access the properties of another tab (page) that you are not currently on.

In DotNetNuke (DNN), you generally are always working with the tab (page) that you are currently on whether it be at the module level or not.  However, on occassion, you might need to access the properties of another tab (page) that you are not currently on.

The DotNetNuke core framework does an absolutely wonderful job of exposing the most commonly needed page, site, and module properties when you are dealing with its programmatic elements, namely module development.  However, we are not always programming within the module scope.  Sometimes, you might be creating a customer provider or custom class to deal with some Business Logic Layer (BLL).

It is during these aforementioned times that we very often need to access certain properties of OTHER tabs when we are not on those tabs.  Here is a method that could very well be of help to you (with overloads):

''' <summary>
''' GetTabInfoByTabId - this method allows you to easily get an instance of a specific tab that you are looking for in the portal using its TabId
''' </summary>
''' <param name="intTabId">Integer - the id number of the tab</param>
''' <returns>DotNetNuke.Entities.Tabs.TabInfo - the object that holds all of the information about a tab</returns>
''' <remarks>
''' This method uses the DesktopTabs collection in the PortalSettings object to locate the tab. It assumes that you intend to use the 
''' current instance of PortalSettings.
''' </remarks>
Overloads Shared Function GetTabInfoByTabId(ByVal intTabId As Integer) As DotNetNuke.Entities.Tabs.TabInfo
    Return GetTabInfoByTabId(intTabId, DotNetNuke.Entities.Portals.PortalController.GetCurrentPortalSettings)
End Function

''' <summary> ''' GetTabInfoByTabId - this method allows you to easily get an instance of a specific tab that you are looking for in the portal using its TabId ''' </summary> ''' <param name="intTabId">Integer - the id number of the tab</param> ''' <param> name="objPortalSettings">DotNetNuke.Entities.Portals.PortalSettings - the object that holds all of the portal settings</param> ''' <returns>DotNetNuke.Entities.Tabs.TabInfo - the object that holds all of the information about a tab</returns> ''' <remarks> ''' This method uses the DesktopTabs collection in the PortalSettings object to locate the tab. ''' </remarks> Overloads Shared Function GetTabInfoByTabId(ByVal intTabId As Integer, ByVal objPortalSettings As DotNetNuke.Entities.Portals.PortalSettings) As DotNetNuke.Entities.Tabs.TabInfo     '     ' BEGIN VALIDATION     '     ' this is using a regex expression in a custom class to check the value     If Not Utilities.RegExLibrary.IsNumber(intTabId) Then _     Throw New ArgumentNullException(" The intTabId argument must be a number")     If objPortalSettings Is Nothing Then _     Throw New ArgumentNullException(" The objPortalSettings argument cannot be null")     '     ' END VALIDATION     '     ' create a tab instance to send back     Dim tab As DotNetNuke.Entities.Tabs.TabInfo = Nothing     ' find the tab that matches the given tabid     For intIndex As Integer = 0 To objPortalSettings.DesktopTabs.Count - 1         tab = CType(objPortalSettings.DesktopTabs(intIndex), Entities.Tabs.TabInfo)         ' if the tab matches, send it back         If tab.TabID = intTabId Then Return tab     Next     ' we should hopefully never hit this return     Return tab End Function

3 comment(s) so far...


Where does this method come from?

Utilities.RegExLibrary.IsNumber(intTabId)

Thanks for this article, it was very helpful.

By Kathleen Ballard on   9/12/2007

This is a method in a custom class of validation methods that I have built for quick and easy argument and data validation. All members use Regular Expression for ease of use, dependability, and performance. I left those lines in there simply to show you that you should be performing checks on the incoming arguments for better error handling and prevention.

By wills on   9/12/2007
Gravatar

Will,

Great post - extremely helpful. It kind of amazes me that we have to iterate through PortalSettings.DesktopTabs just to lookup a tab's info by ID - I swore there had to be a native way to do it without writing one's own logic but I couldn't find a method better than this.

Thanks a million!
Ken

By Ken Tarwood on   9/24/2009

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 
Add to Technorati Favorites
Tweet about my blog
Will Strohl - The Mighty Blog - RSS Feed

Tag Cloud

Sort by:Tag | SizeRSS
camp   community   dnn   dotnetnuke   dotnetnuke®   event   example   free   get   group   integer   jquery   meeting   module   new   odug   orlando   search   session   think  
The opinions expressed here are the personal opinions of Will Strohl and do not necessarily represent the views and opinions of the DotNetNuke Corporation.
© Copyright 2004-2010 by Will Strohl. All rights reserved.Website Skinned By: Ralph Williams  Website Hosted By: Applied Innovations