Click here to Skip to main content
Licence CPOL
First Posted 11 May 2008
Views 11,608
Downloads 68
Bookmarked 18 times

Capture the mouse movement in web service

By | 11 May 2008 | Article
Capture the mouse movement though web service using ASP.NET AJAX.

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

Software Developer
Dubai based company
United Arab Emirates United Arab Emirates

Member

I like to find out new technology in web.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralGood idea PinmemberCoperNick21:12 16 Mar '10  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 11 May 2008
Article Copyright 2008 by Mujibur Rahman
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid