Learn More





Create a new page programmatically

Return to previous page

  • 4/7/2015



Create a new page programmatically

Last updated 4 years ago



(Enter the content of this article below)




In DotNetNuke page's are programmatically known as tabs (this was the legacy term used in the original Ibuyspy code). When operating with pages via code, page instances are stored in the TabInfo class and manipulated via the TabController class, both of which are in the DotNetNuke.Entities.Tabs namespace

Note: The API documentation can be downloaded from the downloads page.

Creating the page via code

Note: When creating a new page via code, it is not sufficent to create the page itself. DotNetNuke implements a rich set of permissions including page permissions (via the TabPermissionCollection), so new pages require permissions to be programatically set otherwise they cannot be navigated to.

To create a page programmatically code similar to the following is used:

Dim controller As New TabController

Dim newTab As New Tabs.TabInfo
Dim newPermissions As TabPermissionCollection = newTab.TabPermissions
Dim permissionProvider As PermissionProvider = permissionProvider.Instance
Dim infPermission As TabPermissionInfo

' set new page properties
newTab.PortalID = PortalId ' the portal you want the page created on
newTab.TabName = PageName 'the new page name
newTab.Title = PageTitle 'the new page title
newTab.Description = Description 'the new page description
newTab.KeyWords = Keywords 'the new page keywords (used for meta keywords and search)
newTab.IsDeleted = False 'whether it is deleted - always false for new pages
newTab.IsSuperTab = False 'whether it should only be accessible by superusers
newTab.IsVisible = True 'whether it is visible
newTab.DisableLink = False 'whether it has a menu link
newTab.IconFile = "" 'the image file used in the menu
newTab.Url = "" 'if the page is a redirection to a URL such as another page or an external site
newTab.ParentId = <insert relevant pageid here - see notes below>

' create new page
controller.AddTab(newTab, LoadDefaultModules)

' copy permissions selected in Permissions collection
For index As Integer = 0 To (Permissions.Count - 1)
infPermission = New TabPermissionInfo

infPermission.AllowAccess = Permissions(index).AllowAccess
infPermission.RoleID = Permissions(index).RoleID
infPermission.RoleName = Permissions(index).RoleName
infPermission.TabID = Permissions(index).TabID
infPermission.PermissionID = Permissions(index).PermissionID

'save permission info
newPermissions.Add(infPermission, True)
Next index

  • Pages require a "parent" page id. Whilst this might be fixed (e.g. create all new pages under a particular page), sometimes code will look to add it under the current page. A popular option for this would be to pull back the tabid for the current module e.g.
    objModuleInfo = objModuleContr.GetModuleByDefinition(PortalId, "UserReg")
    intModTabID = objModuleInfo.TabID
    newTab.ParentId = intModTabID

  • it's of course possible to "clone" a tab, but retrieving it's definition from an existing tab and then saving it elsewhere e.g.
    dim newTab as TabInfo = controller.GetTab(oldTabId, portalID, true)
    . However, if doing this on versions 5.5.0 or higher, please ensure that you change the uniqueID value i.e newTab.UniqueId = System.Guid.NewGuid()

  • if you purely want a clone of a tab then the TabController already has the handy, if not very flexible, TabController.CopyTab method.

Useful references

No sections defined
Try Evoq
For Free
Start Free Trial
a Demo
See Evoq Live
Need More Information?