to get collection of ImageButton controls in code behind page

Posted on 2007-07-20
Last Modified: 2011-10-03
I need to apply rollover effect to buttons on my aspx page. I am using javascript function for that in which I use onMouseUp and onMouseDown events for the rollover effect. I have lots of controls and so I want collection of the ImageButton controls in code behind page to apply onMouseUp and onMouseDown events for them. Plz let me know how to get the collection of controls in code behind page and how to apply events for this collection.
Question by:Econify
    LVL 96

    Accepted Solution

    VB.NET example:

        Dim form As HtmlControls.HtmlForm = Me.FindControl("form1")
        For Each ctl As Control In form.Controls
          If TypeOf ctl Is ImageButton Then
          End If

    LVL 9

    Assisted Solution

    Bob's solution above will get the collection, to apply the javascript events:

    If TypeOf ctl Is ImageButton Then
           ctl.Attributes.Add("OnMouseOver", "this.className='ibover';")
           ctl.Attributes.Add("OnMouseOut", "this.className='ibnormal';")
    End IF

    Substitute ibover and ibnormal for your CSS Classes.
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now