To get the alert, I clicked on the div 80 pixels from the left side.

Output
domevent.png

ASPX page
<asp:Panel runat="server" ID="pnlTest" BorderColor="Blue" BorderWidth="3">
	<asp:Label runat="server" ID="lblTest" Text="Test" />
</asp:Panel>
<axial:WFStartupScript runat="server" MethodName="Startup" />


Codebehind
public struct Point
{
	public int X;
	public int Y;
}

public partial class DomEvent : System.Web.UI.Page
{
	public void Startup()
	{
		pnlTest.AddHandler(ClientEvent.MouseDown, AlertSomething);
	}

	public bool AlertSomething(Event e)
	{
		Window.Alert("cursor x: " + GetPosition(e).X);
		return true;
	}

	public Point GetPosition(Event e)
	{
		e = e ?? Window.Event;
		var cursor = new Point { X = 0, Y = 0 };
		if (e.PageX != null)
		{
			cursor.X = e.PageX.Value;
			cursor.Y = e.PageY.Value;
		}
		else
		{
			cursor.X = e.ClientX +
				(Document.DocumentElement.ScrollLeft ?? Document.Body.ScrollLeft).Value -
				Document.DocumentElement.ClientLeft;
			cursor.Y = e.ClientY +
				(Document.DocumentElement.ScrollTop ?? Document.Body.ScrollTop).Value -
				Document.DocumentElement.ClientTop;
		}
		return cursor;
	}
}

Last edited Aug 5, 2008 at 8:33 PM by thasmin, version 2

Comments

No comments yet.