lee2006
04-04-2007, 02:04 PM
Hi there I am having problems with adding an click event handler to some image buttons that are created programmticly using asp.net and vb.
I create the images from an xml file depending on the image tags contaned within, this works fine and dispplays the images on the screen.
But i want the images to be clickable to view a larger image, so i need to be able to point to the clickevent handler on the fly.
I have read loads of posts and tutorilas and they all say to point to a handler in vb just add the following line
AddHandler himage.Click, AddressOf btn_click
So i addid this to the creation of the image buttons, it dosent throw any errors but all that happens is the page is reloaded, the event handler is not fired, i have tested it, the code snippet is bellow:-
'loop for all image found in xml list
For a = 0 To himgcount - 1
' create new image instance and set variables
Dim himage As New ImageButton
himage.Width = 70
himage.Height = 70
himage.CssClass = "cimage"
himage.ID = "test" + a.ToString
'set images location from xml
himage.ImageUrl = imagepath & histimagexmn(a).Attributes("ipath").Value.Trim
'set image tool tip from xml atribute and trim white space
himage.ToolTip = histimagexmn(a).Attributes("toolt").Value.Trim
'set image alternate text from xml atribute and trim white space
himage.AlternateText = histimagexmn(a).Attributes("toolt").Value.Trim
AddHandler himage.Click, AddressOf btn_click
'add image to panel
hist_pnl.Controls.Add(himage)
Next a
and the event handler is as follows
Private Sub btn_click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
//code to run in here
End Sub
Anyone have any ideas as I am fresh out and cant fined anythig else, this apparently should work, but as stated the event handler does not fire and the imagebuttons are linked back to the same page so it relods, even though i havent specified that.
Please help
Thanks
Lee
I create the images from an xml file depending on the image tags contaned within, this works fine and dispplays the images on the screen.
But i want the images to be clickable to view a larger image, so i need to be able to point to the clickevent handler on the fly.
I have read loads of posts and tutorilas and they all say to point to a handler in vb just add the following line
AddHandler himage.Click, AddressOf btn_click
So i addid this to the creation of the image buttons, it dosent throw any errors but all that happens is the page is reloaded, the event handler is not fired, i have tested it, the code snippet is bellow:-
'loop for all image found in xml list
For a = 0 To himgcount - 1
' create new image instance and set variables
Dim himage As New ImageButton
himage.Width = 70
himage.Height = 70
himage.CssClass = "cimage"
himage.ID = "test" + a.ToString
'set images location from xml
himage.ImageUrl = imagepath & histimagexmn(a).Attributes("ipath").Value.Trim
'set image tool tip from xml atribute and trim white space
himage.ToolTip = histimagexmn(a).Attributes("toolt").Value.Trim
'set image alternate text from xml atribute and trim white space
himage.AlternateText = histimagexmn(a).Attributes("toolt").Value.Trim
AddHandler himage.Click, AddressOf btn_click
'add image to panel
hist_pnl.Controls.Add(himage)
Next a
and the event handler is as follows
Private Sub btn_click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
//code to run in here
End Sub
Anyone have any ideas as I am fresh out and cant fined anythig else, this apparently should work, but as stated the event handler does not fire and the imagebuttons are linked back to the same page so it relods, even though i havent specified that.
Please help
Thanks
Lee