Dynamically Create AddressOf for ImageButton

S

Scott

Please help.

I have ImageButtons that are created dynamically and the event to be
called onclick of the button is stored in a database. The event
itself will be prewritten, however it is on a separate .vb page than
the aspx.vb codebehind file. I have not been able to get the button
to fire the event. here is the code:

Dim button as new imageButton
button.imageURL=image.gif
button.ID="buttonName"
AddHandler button.click, AddressOf btnLookup_Click


A separate section in the same .vb file is:
Protected Sub btnLDAPLookup_Click(ByVal s As Object, ByVal e As
EventArgs)
DO SOMETHING
End Sub

What am I doing wrong? Should it be a protected sub? Does it matter
that the sub is located in a .vb file, with the button initialization,
that is not the same aspx.vb file?

Any help is greatly appreciated.
 
G

Guest

To add more detail I have copied and pasted the code below:

Public Shared Function getImageButton(ByVal buttonID As Integer, ByVal
imagePath As String)

Dim button As New ImageButton
Dim buttonDB As New SAFE.SAFEFunctions
Dim dbconnButton As IDbConnection = Nothing
Dim buttonReader As SqlDataReader
dbconnButton = buttonDB.GetConnection
dbconnButton.Open()
Dim getButtonSQL As String
getButtonSQL = SAFE.SAFEFunctions.getRequestItemDetail(buttonID)
Dim getButtonCommand As New SqlCommand(getButtonSQL, dbconnButton)
buttonReader = getButtonCommand.ExecuteReader
Do While buttonReader.Read
Select Case
buttonReader("RequestConfigurationObjectTypePropertiesID")
Case 8 'image source

button.ImageUrl = imagePath &
buttonReader("RequestObjectValue")
Case 22 'Alt Text
button.AlternateText =
buttonReader("RequestObjectValue")
Case 23 'ID
button.ID = buttonReader("RequestObjectValue")
Case 24 'On Click Event

AddHandler button.Click, AddressOf
btnLDAPLookup_Click()


End Select
Loop

buttonReader.Close()
getButtonCommand.Dispose()
dbconnButton.Close()
Return button
End Function

The btnLDAPLookup_Click is as follows:
Private Sub btnLDAPLookup_Click(ByVal s As Object, ByVal e As EventArgs)
do something here...
End Sub

Remember, these are both in the same .vb file, but not the aspx.vb for this
page. However, the function is called during the PageLoad function so I
thought this should work.

Again, any help is greatly appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top