We help IT Professionals succeed at work.

Need help getting event handler to fire in vb.net web form

Last Modified: 2013-11-07
I am having trouble getting an event to fire for this code.   Can somebody please tell me what I am doing wrong?  This is in vb.net 2.0 on a web form.

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        Dim dsPictures As New DataSet
        Dim rowPictures As DataRow
        dsPictures = GetDS("Select stocknumber,picnumber from vehiclePics where stocknumber='" + DropDownList1.SelectedValue.ToString + "'", PicDB)
        For Each rowPictures In dsPictures.Tables(0).Rows
            Dim button As New ImageButton
            button.ImageUrl = "Pictures/stockpic.aspx?SN=" + rowPictures.Item("Stocknumber").ToString + "&N=" + rowPictures.Item("picnumber").ToString
            AddHandler button.Click, AddressOf ImageButton_Click
    End Sub

Public Sub ImageButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        Dim button As ImageButton = CType(sender, ImageButton)
        Dim stocknumber As String
        stocknumber = button.ImageUrl.ToString
    End Sub

Thanks in advance.
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.