directxBOB
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?
<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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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?
ASKER
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSourc e1" OnItemCommand="Repeater_It emCommand" >
<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. ImageButto n = TryCast(e.CommandSource, System.Web.UI.WebControls. ImageButto n)
Session.Add("LastLinkClick ed", 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.
<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
Try
Dim Image As System.Web.UI.WebControls.
Session.Add("LastLinkClick
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@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?
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?
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.