Eeeek!
What happened to my lovely formatting???
In search of a nicer format... here's the code again, including the new If statement highlighted in Red.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Obtain PortalSettings from Current Context
Dim _portalSettings As PortalSettings = CType(HttpContext.Current.Items("PortalSettings"), PortalSettings)
Dim it As String
it = "Test text "
Try
' Get settings from the database
Dim settings As Hashtable = PortalSettings.GetModuleSettings(ModuleId)
it += "1"
If (Page.IsPostBack = False) Then
lblMessage.Text = ""
' get a list of repository modules on this portal
ddlRepositoryID.Items.Clear()
it += "2"
Dim repositories As New RepositoryController
Dim tabs As New TabController
Dim arrModules As New ArrayList
Dim objTab As TabInfo
Dim objModule As ModuleInfo
Dim objItem As ListItem
it += "3"
arrModules = repositories.GetRepositoryModules(_portalSettings.PortalId)
it += "3a"
For Each objModule In arrModules
' Note - this method is deprecated
objTab = tabs.GetTab(objModule.TabID)
it += "4"
' Added this If statement to protect against Null References from dangling (homeless?) repositories
If Not objTab Is Nothing Then
objItem = New ListItem
objItem.Text = objTab.TabName & " / " & objModule.ModuleTitle
it += "4a"
objItem.Value = objModule.ModuleID
ddlRepositoryID.Items.Add(objItem)
End If
Next
it += "5"
objItem = New ListItem
objItem.Text = "Select Tab/Repository"
objItem.Value = ""
ddlRepositoryID.Items.Insert(0, objItem)
it += "6"
If CType(settings("repository"), String) <> "" Then
ddlRepositoryID.SelectedValue = CInt(CType(settings("repository"), String))
End If
it += "7"
If CType(settings("rowcount"), String) <> "" Then
txtRowCount.Text = CType(settings("rowcount"), String)
End If
it += "8"
If CType(settings("style"), String) <> "" Then
rbStyle.SelectedValue = CType(settings("style"), String)
End If
it += "9"
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(it, Me, exc, True)
End Try
' Localization
rbStyle.Items(0).Text = Localization.GetString("CategoryListing", LocalResourceFile)
rbStyle.Items(1).Text = Localization.GetString("MultiColumnCategoryListing", LocalResourceFile)
rbStyle.Items(2).Text = Localization.GetString("LatestUploads", LocalResourceFile)
rbStyle.Items(3).Text = Localization.GetString("TopDownloads", LocalResourceFile)
rbStyle.Items(4).Text = Localization.GetString("TopRated", LocalResourceFile)
End Sub