Click here to Skip to main content
6,822,123 members and growing! (17,930 online)
Email Password   helpLost your password?
Web Development » Ajax and Atlas » General License: The Code Project Open License (CPOL)

Capture the mouse movement in web service

By Mujibur Rahman

Capture the mouse movement though web service using ASP.NET AJAX.
Javascript, CSS, HTML, XHTML, ASP, ASP.NET, WebForms, Ajax
Posted:11 May 2008
Views:7,398
Bookmarked:13 times
Unedited contribution
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
1 vote for this article.
Popularity: 0.00 Rating: 1.00 out of 5
1 vote, 100.0%
1

2

3

4

5

Introduction

Capture the mouse movement though web service using AJAX. The beauty for web service is, you can call the web service through javascript function and you can interact with database. Here i develop simple web page which display a image inside the div tag. If you move this image the latest position will captured by web service and the information will store in the database without page loading..

Using the code

Web service(Service_Position.asmx)
Make a new ajax enabled website in VS 2005. Create a web service with the name 'Service_Position.asmx' . Add the System.Web.Script.Services.ScriptService attribute to the service class. This attribute enables access to the Web service from ASP.NET AJAX client side code. In 'StorePos1' function, am passing 2 parameters x and y.

//
// Service_Position.asmx
//
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()> _
Public Class Service_Position
Inherits System.Web.Services.WebService
<WebMethod(EnableSession:=True)> _
Public Function StorePos1(ByVal x, ByVal y) As String
Dim posX As String
Dim posY As String
posX = x
posY = y
'StoreinDB(x, y)
Return "1"
End Function
End Class
		

Create a file called 'Default.aspx'. Create one div control and one image control.

<div id="lay1" runat="server" class="displayretainer" style=" left: 270px; width: auto; text-indent: 15px; position: absolute; top: 158px; height: auto; text-align: center; cursor:move;" onMouseDown="Move(this,'Img1')">
<asp:Image ID="Img1" ImageUrl="smiley1_tn.gif" runat="server" /> 
</div>

In mousedown event, we are getting the x and y position and send this to web service.

Service_Position.StorePos1(x1,y1); 

In script manager we have to refere the webservice file.

<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/Service_Position.asmx" />
</Services>
</asp:ScriptManager>
thats it. Now move the image object around the screen and check your database how its captured.

Points of Interest

This concept am using for my new project online T-Shirt designer. Its a simple and useful idea.

History

N/A

License

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

About the Author

Mujibur Rahman


Member
I like to find out new technology in web.
Occupation: Software Developer
Company: Dubai based company
Location: United Arab Emirates United Arab Emirates

Other popular Ajax and Atlas articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.

PermaLink | Privacy | Terms of Use
Last Updated: 11 May 2008
Editor:
Copyright 2008 by Mujibur Rahman
Everything else Copyright © CodeProject, 1999-2010
Web20 | Advertise on the Code Project