pstanford
asked on
Convert ASPX pagename to Page Control
With previous assistance from Experts Exchange members I've written a recursive routine to loop through all the controls on an ASP.NET 1.1 page to assign images and tooltips from a database.
I want to be able to do the same thing from a generic page, i.e. to let an administrative user see all the controls on a selected page and add image urls and/or tooltips. The problem I can't resolve is how to convert the page name I have in a listbox, e.g. MCR.aspx, back into a Page Control to pass to this routine instead of passing the varialble 'Me'. I know how to get the ID and ClientID to get the actual page name (MCR.aspx) but not how to do this in reverse.
I display a list of all the Page names, then when I select one I want call a routine that looks something like this:
I'm sure it's not too difficult for someone with more experience but any assistance will be greatly appreciated.
'-------------------------------------------------------------------------------
' Recursively set the ImageUrl and ToolTip for Images and Image Buttons
' together with the ToolTip for Mandatory fields. This is a modified version
' that gets the tooltip from the ToolTips table and the ImageURL from the
' ControlNames table
'-------------------------------------------------------------------------------
Public Sub SetIconImages(ByVal Page As Control, ByVal WebPageName As String)
For Each ctrl As Control In Page.Controls
If TypeOf ctrl Is ImageButton Then
CType(ctrl, ImageButton).ImageUrl = GetSpecificImageURL(ctrl.ID.ToString)
CType(ctrl, ImageButton).ToolTip = GetSpecificToolTip(WebPageName, ctrl.ID.ToString)
ElseIf TypeOf ctrl Is Image Then
If Left(ctrl.ID.ToString, 4) = "tti_" Then
CType(ctrl, Image).ImageUrl = GetSpecificImageURL(ctrl.ID.ToString)
CType(ctrl, Image).ToolTip = GetSpecificToolTip(WebPageName, ctrl.ID.ToString)
End If
If System.Configuration.ConfigurationSettings.AppSettings(ctrl.ID.ToString) Is Nothing Then
CType(ctrl, Image).AlternateText = "Assign an Image in the Web.config file to this key: " + ctrl.ID.ToString
Else
CType(ctrl, Image).ImageUrl = System.Configuration.ConfigurationSettings.AppSettings(ctrl.ID.ToString)
End If
ElseIf TypeOf ctrl Is Label Then
If CType(ctrl, Label).Text = "M" Then
CType(ctrl, Label).ForeColor = Drawing.Color.Silver
CType(ctrl, Label).ToolTip = "Mandatory Field: This will turn red if invalid or incomplete data is detected"
ElseIf CType(ctrl, Label).Text = "9" Or CType(ctrl, Label).Text = "D" Or CType(ctrl, Label).TemplateSourceDirectory = "V" Then
CType(ctrl, Label).ForeColor = Drawing.Color.Silver
CType(ctrl, Label).ToolTip = "Optional Field: This will turn red if invalid or incomplete data is detected"
End If
Else
If ctrl.Controls.Count > 0 Then
SetIconImages(ctrl, WebPageName)
End If
End If
Next
End Sub
. This is called from each page when it is first loaded and works fine.
With clsGenericFunctions.GetInstance
.SetIconImages(Me, .GetCurrentPageName)
End With
I want to be able to do the same thing from a generic page, i.e. to let an administrative user see all the controls on a selected page and add image urls and/or tooltips. The problem I can't resolve is how to convert the page name I have in a listbox, e.g. MCR.aspx, back into a Page Control to pass to this routine instead of passing the varialble 'Me'. I know how to get the ID and ClientID to get the actual page name (MCR.aspx) but not how to do this in reverse.
I display a list of all the Page names, then when I select one I want call a routine that looks something like this:
Public Sub GetControlNames(ByVal Page As Control, ByVal WebPageName As String, ByVal ArrayCtrl As ArrayList)
For Each ctrl As Control In Page.Controls
. The Page variable needs to be the equivalent of {asp.MCR_aspx} as a Control but I can't get this conversion to work.I'm sure it's not too difficult for someone with more experience but any assistance will be greatly appreciated.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks about that.
In the end, whatever the choice you are making, it is yours and it has to answer your specific contraints, after all you are the one coding.
Hava a Nice day.
Julien
In the end, whatever the choice you are making, it is yours and it has to answer your specific contraints, after all you are the one coding.
Hava a Nice day.
Julien
ASKER
The techniques were useful but none of them were implemented in order to address the problem
ASKER
The second table (WebPageNames) contains names of the .aspx pages within the application.
The third table (ToolTips) contains references to the WebPageNames and ControlNames tables, i.e. the same control can be used on multiple pages with the same image (for Image Buttons and Images) but a different ToolTip, depending on the context.
I can, using a routine similar to the one contained in the first post, iterate through the controls on any given page and get the names of those controls, look up both the image and the tooltip and apply them dynamically at runtime. If I build that functionality into each of the pages I can also push any control names back into the database and also into the link table.
I was just hoping to be able to do this in one generic function rather than having to repeat the code, so while I'm sure your solution is architecturally way more elegant than mine, this is an internal application with a known number of users and I just want the administrator to control the tooltips that are applied rather than hardcode them into the application.
I've manually created the entries in the ControlNames and WebPageNames tables but it seems like there must be a simpler way to do this through a generic routine that I call from each page rather than coding on each page. The following images show samples of the data in the ControlNames and ToolTips tables.
This application will ultimately be replaced by a new Silverlight application so I don't want to waste too much time on it and only an Administrator would load a page and request a list of Controls from a different page so there wouldn't be a performance issue. I'd just like to now how to do this using a generic routine.
I do appreciate your response but don't think it addresses the issue as simply as I'd like it to do.