Hi!
I am trying to create a navigation user control using image buttons, and I have "on" and "off" versions of each button.
I would like to write code to dynamically switch out the Image URL of the clicked image button, turning the clicked button "on" and turning all the other selected buttons "off". Another reason I want to accomplish this dynamically is so that I can call this method from external pages when the user control loads.
My code and HTML is included below. Any help would be greatly appreciated!
<table style="text-align:center;width:100%"><tr style="vertical-align:middle"><td>
<asp:ImageButton ID="draft" runat="server" ImageUrl="~/images/vcnav_draft_off.png" />
</td><td>
<asp:ImageButton ID="review" runat="server" ImageUrl="~/images/vcnav_review_off.png" />
</td><td>
<asp:ImageButton ID="print" runat="server" ImageUrl="~/images/vcnav_print_off.png" />
</td><td>
<asp:ImageButton ID="sign" runat="server" ImageUrl="~/images/vcnav_sign_off.png" />
</td><td>
<asp:ImageButton ID="send" runat="server" ImageUrl="~/images/vcnav_send_off.png" />
</td></tr></table>Protected Sub draft_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles draft.Click
SetActiveButton(
"draft")Response.Redirect("vcwname.aspx")
End Sub
Public Sub SetActiveButton(ByVal sButtonID As String)
For Each c As Control In Me.Page.Controls
If TypeOf c Is ImageButton ThenDim im As ImageButton = DirectCast(c.FindControl(c.ID), ImageButton)
If im.ID = sButtonID Then
im.ImageUrl =
"~/images/vcnav_" & sButtonID & "_on.png"
Else
im.ImageUrl =
"~/images/vcnav_" & sButtonID & "_off.png"
End If
c = im
End IfNext c
End Sub