locked
Addind Handler for controls added at page load RRS feed

  • Question

  • User-1007884948 posted

    i am wanting to add handler for controls i add at Page_load


    at page load i added several image buttons and applied the image urls using -i used the borderwidth propertiy for padding as was having trouble getting a cssclass to work.

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim imagepath As DirectoryInfo = New DirectoryInfo(Server.MapPath("~/Images"))
            For Each _imageFile As FileInfo In imagepath.GetFiles()
                Dim imgbutton As New ImageButton
                imgbutton.Width = 100
                imgbutton.Height = 100
                imgbutton.BorderWidth = 10
                imgbutton.BorderColor = Drawing.Color.Black
                imgbutton.ID = _imageFile.ToString
                imgbutton.ImageUrl = imagepath.FullName & "/" & imgbutton.ID.ToString
                ThumbPanel.Controls.Add(imgbutton)
    
            Next
        End Sub
    
    what i want these Image button to do is when clicked  a larger image in another panel will  appear so i will need to assign the clicked buttons image url to the large image controls, image url

    Thursday, August 5, 2010 11:28 AM

Answers

  • User-653327211 posted

    Here is some code to capture the event:

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim imgButton As New ImageButton
            AddHandler imgButton.Click, AddressOf imgButtonClicked
        End Sub
    
        Public Sub imgButtonClicked(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
            'sender will equal the button that was clicked
        End Sub


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 5, 2010 12:40 PM

All replies

  • User-653327211 posted

    Here is some code to capture the event:

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim imgButton As New ImageButton
            AddHandler imgButton.Click, AddressOf imgButtonClicked
        End Sub
    
        Public Sub imgButtonClicked(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
            'sender will equal the button that was clicked
        End Sub


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 5, 2010 12:40 PM
  • User-1007884948 posted

    Cool thanks i had a feeling it was something like that but was unsure

    Thursday, August 5, 2010 12:54 PM