to get collection of ImageButton controls in code behind page

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.
EconifyAsked:
Who is Participating?
 
Bob LearnedCommented:
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
    Next

Bob
0
 
traxionCommented:
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.
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.