ImageButton bug

B

beanweed

The click event arguments 'x' and 'y' are wrong if the dpi setting is not
96dpi.

Here is the code for a ImageButton control sample:

<%@ Page Language="VB" %>
<html>
<head>
<script language="VB" runat="server">
Sub ImageButton_Click(sender As Object, e As ImageClickEventArgs)
Label1.Text = "Coordinates: " & e.X.ToString() & "," & e.Y.ToString() &
")"
End Sub
</script>
</head>
<body>
<form runat="server">
<asp:ImageButton id="imagebutton1" runat="server"
ImageAlign="left"
ImageUrl="anyimage.jpg"
Width="200"
Height="300"
OnClick="ImageButton_Click"/>
<br><br>
<asp:label id="Label1" runat="server"/>
</form>
</body>
</html>

Note that the width and height are set. I have also used CSStyle (by itself
and with Width/Height) to constrain the size.

At the normal font setting of 96dpi the image is the correct size and the
maximum "Coordinates:" is 199,299. But if the font setting is large (125% or
120dpi, like a laptop) then the image is 200 by 300 pixels, even if it looks
smaller on the screen, but I can click on "Coordinates:249,374". I don't see
how it is possible for me to have an x and y that are beyond the size of the
image! In the alternative, how could one get the dpi setting of the client
machine and scale the e.x, e.y values?
 
T

Teemu Keiski

ImageButton in fact reads only what browser sends as arguments (I assume you
tried it with IE). Did you try with other browsers that what the results are
with them?
 
B

beanweed

In Netscape, the coordinates are correct: if the dpi or screen size change,
the image size changes to accomodate and the maximum coordinates are always
the same. However,it ignores the size settings. It is crucial that the image
be the given size since the X and Y are used to look-up a value in an xml
document. I can and have made the image the correct size and this seems to
work, but I would rather be able to set the size using Width/Height or CSS.

I regret that I haven't tested in browsers other than Netscape and IE.

About 90% of my organization's users are using IE, so it will have to work
there at least. If I write a javascript to show the coordinates onmouseover,
it shows that the "event.x" and "event.y" at the bottom-right are 200,300,
regardless of the dpi or screen size. So why then does "e.X" and "e.Y" come
to be greater than that?
 
T

Teemu Keiski

Just out of interest, did you try to restart IE after changing those
settings? (just interested if it has effect). I remember sometimes seeing
that those don't get updated correctly without browser restart. :)

You could also try asking this in IE newsgroups.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top