Link to home
Start Free TrialLog in
Avatar of directxBOB
directxBOBFlag for Ireland

asked on

Image Button Click ?

I have the following code:

 <li><a>
<asp:ImageButton ID="imgLogin" ImageUrl='<%# Bind("Image") %>' runat="server" PostBackUrl='<%# Bind("Path") %>'
AlternateText='<%# Bind("AltText") %>' OnClick="ImageButton_Click" />
</a>
</li>

I use the <a></a> so that I can change the background image via CSS.

Basically all I want to do is have : OnClientClick call the code behind:

    Public Sub ImageButton_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
....
....
    End Sub

Any ideas?
SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of urir10
urir10

You mean you want to run code behind and redirect the page to another url? if so you cannot do it that way but you can redirect the  page in Code Behind.
Avatar of directxBOB

ASKER

I can, even when I remove the <a></a> the event is not called. Is this as a result of the image buttons being within a repeater?
The above list is a menu system built from a asp:repeater

I want the OnClick Event to call the same method in the code behind so that I can capture the name of the button last clicked.

In the DataBound I will then check the session for the last clicked and change the background of the image to a differnt color.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
                       <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemCommand="Repeater_ItemCommand">
                            <HeaderTemplate>
                                <ul id="navbar">
                            </HeaderTemplate>
                            <ItemTemplate>
                                <li><span>
                                    <asp:ImageButton ID="imgLogin" ImageUrl='<%# Bind("Image") %>' runat="server" PostBackUrl='<%# Bind("Path") %>'
                                        AlternateText='<%# Bind("AltText") %>' /></span> </li>
                            </ItemTemplate>
                            <FooterTemplate>
                                </ul>
                            </FooterTemplate>
                        </asp:Repeater>


codebehind:


    Protected Sub Repeater_ItemCommand(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs)

        Try
            Dim Image As System.Web.UI.WebControls.ImageButton = TryCast(e.CommandSource, System.Web.UI.WebControls.ImageButton)
            Session.Add("LastLinkClicked", Image.ID)
        Catch ex As Exception

        End Try

    End Sub

For some reason the event doesn't kick off each every time you click a button.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@revaluser

Unfortunately I cannot use javascript. It's a development policy.... don't ask :(

Anyway to narrow this down a little further basically it appears the that ItemCommand isn't being called because the ImageButton has already navigated away from the page. So if I click the link that the page is already on then it gets called...

So any other alternatives?
Currently Trying to get this working with DataBound Event. Basically checking to see if the URL matches that as one of the imagebuttons, if so I save it in a session  and set the backgrouond image for that imagebutton in the session.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial