I have a situation. I am using web application of windows(ASP.NET). On page load when my web page appears, it has dynamically generated ImageButtons. I need to fid the X,Y or TOP,LEFT co-ordinates of each ImageButton control on the page WITHOUT CLICKING ON ANY OF THE ImageButtons.. I need to draw a line beetween some ImageButtons on the click of one ImageButton.
Asked
Active
Viewed 835 times
1 Answers
0
Try using some Javascript code or jQuery. Please find below jQuery code
Here i have used position() method which gives you left and top position of the element. You can change the selector based on your need.
Update: Assumed you have HTML like <div id='images-container'> .. all images here </div>
and updated selector below for that with each() method
You can also use offset()
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$('#images-container img').each(funcion(){
var coordinates=$(this).position();
coordinates.left;// gives you x
coordinates.top;// gives you y
//save these values in some hidden field and access it in code behind if needed
});
});
</script>
Please refer this post for more information jQuery x y document coordinates of DOM object

Community
- 1
- 1

Murali Murugesan
- 22,423
- 17
- 73
- 120
-
@Murli : Thanks Murli. Does this gives me the co-ordinates of each ImageButton that I have on my we Form.? And how to use these values in my C# code – Nov 19 '12 at 09:42
-
This code gives the first image button. If you want to take all image button you simply use image selector. $('#images-container img').position() -> this gives all images inside any container like div which is having id='images-container' – Murali Murugesan Nov 19 '12 at 09:49
-
@Murli : How do i do it for the ImageButtons which are generated purely dynamically.? There is no div in .aspx. Everything is generated in .CS file. How to apply abive code in .Cs file. How to use jquery in .CS file.? Plz help. – Nov 20 '12 at 03:58