5,695,118 members and growing! (14,743 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, WebForms, Ajax, ASP, ASP.NET

Posted: 11 May 2008
Updated: 11 May 2008
Views: 3,494
Bookmarked: 5 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
1 vote for this Article.
Popularity: 0.00 Rating: 1.00 out of 5
1 vote, 100.0%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
0 votes, 0.0%
4
0 votes, 0.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

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


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
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 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   

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