Click here to Skip to main content
15,894,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am trying to get the location of a click within an image button inside a datalist.
I am thinking my two options are to pass in the location of a click into the CommandArgument or get it from the DataListCommandEventArgs.



The code I have is below.

<asp:ImageButton runat="server" ID="imgThumbnail" Width ="225px" Height ="338px" ImageUrl='<%# DataBinder.Eval(Container.DataItem,"IMAGEFILE") %>'
                                CommandArgument='<%# Eval("CATALOG_ID").ToString + ";" + Eval("BINNUMBER")%>' CommandName="click" style="border:solid"  />


Protected Sub dlItems_ItemCommand(source As Object, e As DataListCommandEventArgs) Handles dlItems.ItemCommand


What I have tried:

I am able to get the location if a click of a standalone imagebutton using ImageClickEventArgs.
Posted
Updated 20-Jan-21 8:40am
Comments
Christian Graus 19-Jan-21 20:58pm    
You need to catch the click and then work out where that is in the image
boyson14 20-Jan-21 9:39am    
I am able catching the click event and tell which image button was clicked. I cannot figure out how to tell where on the image it was clicked.
Christian Graus 20-Jan-21 15:43pm    
So if you have the position of your image, say it's at 145, 20, and you have your mouse click position, normalised to your window, then you subtract the image position from the click location
boyson14 20-Jan-21 16:30pm    
I did not know how to get the coordinates because it was in a datalist. I ended up getting the position of the click using the imagebutton click event saving it in session variables. After that event fires, the itemcommand fires and I can do the things I need to do in there.
Christian Graus 20-Jan-21 16:32pm    
Awesome :)

1 solution

I was able to find the solution below , but I have a feeling there is a better way to do it.

I use the ImageButton's click event to get the location of the click and store it in Session variables. Then I use the session varaibles in the Datalist Itemcommand to make the appropriate changes I need to make to other datalist items.
 
Share this answer
 
Comments
Christian Graus 20-Jan-21 16:32pm    
Wait, you're in a website?
boyson14 20-Jan-21 17:02pm    
Yes, it is ASP.Net. I still don't think it is the right way to do it.
Christian Graus 20-Jan-21 17:04pm    
Sorry, I missed that.
boyson14 20-Jan-21 17:05pm    
No problem. I should of made it clearer. Thanks for the reply.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900