Trace Mouse Coordinate in ASP.NET


Introduction

As we have seen in many windows applications, basically in drawing applications like CorelDraw, displays the coordinate location of mouse. When we move our mouse it frequently changes its location. But we never seen such in ASP.Net like web applications. It is very easy to trace the mouse location in ASP.Net. Let's take a look at simple project code to create it. 

Development

In this project, we have only a Default.aspx page and we will write the codes in the body section of the page under div tag.

HTML Coding


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Display Mouse Coordinate</title>
</head>
<body>
<form id="form1" runat="server">
<div>

<div id="mouse_location">
<strong><span style="color: #0000ff">Look at the Status Bar to see the location of your mouse.
<script type="text/javascript">
function location_trap(e)
{
        if (document.layers)
        {
        xCoord = e.x;
        yCoord = e.y;
        }
        else if (document.all)
        {
        xCoord = event.clientX;
        yCoord = event.clientY;
        }
        else if (document.getElementById)
        {
        xCoord = e.clientX;
        yCoord = e.clientY;
        }
        self.status = "Location X: "  xCoord   "  and Location Y: "   yCoord;
}
document.onmousemove = location_trap;
if(document.captureEvents)
    {
    document.captureEvents(Event.MOUSEMOVE);
    }
</script>

    </span></strong>
</div>  
   
</div>
</form>
</body>
</html>



After writing the above codes we can see our mouse coordinte location in Status Bar of the web page. Look at the screenshort: 

Comments

Popular posts from this blog

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples