Passing a web page as a parameter

Joined
Feb 12, 2006
Messages
18
Location
Australia
Programming Experience
10+
I need to dynamically search a web page and locate imagebuttons without showing the page. The routine that performs the search is in a shared class. Other code in the same shared class works correctly but the difference is that I'm trying to pass the web page as a parameter to the second procedure.

The first procedure works and is called like this:

With clsGenericFunctions.GetInstance
.SetIconImages(
Me, "Form1")
End With
'-------------------------------------------------------------------------------
' This procedure iterates through the Imagebutton controls on the designated
' page and sets the image to a value stored in the web.config file. It also sets
' the corresponding ToolTip text.
'-------------------------------------------------------------------------------
Public Sub SetIconImages(ByVal PageName As System.Web.UI.Page, ByVal PageID As String)
Dim img As Image = New Image
Dim btn As ImageButton = New ImageButton
Dim formctrl As Control = PageName.FindControl(PageID)
For Each ctrl As Control In formctrl.Controls
Try
If TypeOf ctrl Is ImageButton Then
btn = CType(ctrl, ImageButton)
btn.ImageUrl = System.Configuration.ConfigurationSettings.AppSettings(ctrl.ID.ToString)
btn.ToolTip = System.Configuration.ConfigurationSettings.AppSettings(ctrl.ID.ToString + "ToolTip")
Else
If TypeOf ctrl Is Image Then
img = CType(ctrl, Image)
img.ImageUrl = System.Configuration.ConfigurationSettings.AppSettings(ctrl.ID.ToString)
End If
End If
Catch
End Try
Next
End Sub

The second procedure doesn't work is called like this:

With clsGenericFunctions.GetInstance
Dim PageName As System.Web.UI.Page
PageName =
New DocumentAmendment
.GetButtonNames(PageName, "Form1", lstButtonName)
PageName =
Nothing
End With

Public Sub GetButtonNames(ByVal PageName As System.Web.UI.Page, ByVal PageID As String, ByVal ButtonList As ListBox)
With ButtonList
.Items.Clear()
End With
Dim btn As ImageButton = New ImageButton
Dim formctrl As Control = PageName.FindControl(PageID)

The variable formCtrl is set to nothing when debugging

For Each ctrl As Control In formctrl.Controls
Try
If TypeOf ctrl Is ImageButton Then
btn = CType(ctrl, ImageButton)
ButtonList.Items.Add(btn.ID.ToString)
End If
Catch
End Try
Next
End Sub
 
Back
Top