I am new to ASP.NET
I want to implement the website about..
- draw(add) some points. (the number of points: depend on user★)
- user move these points within gray box
- upload locations(top, left) of these points into Database.
I understood how to add draggable points and get coordination of these.
And I want to know..
how to pass some values to codebehind part without reload pages.
how to pass values and use these without knowing how many value it is.
Could you give me some advice or some link about my question?
Thank you in advance.
here is my code.
You can check this out in here (http://jsfiddle.net/crisply/mQYVY/21/)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="jQueryDraggable.aspx.cs" Inherits="WebPage.Tests.jQueryDraggable" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript" src="../Scripts/jquery-1.8.2.js"></script>
<script type="text/javascript" src="../Scripts/jquery-ui-1.8.24.js"></script>
<style type="text/css">
.draggable {
position: absolute;
width: 10px;
height: 10px;
background: green;
cursor: move;
}
.canvas {
width: 500px;
height: 400px;
background: #ccc;
position: relative;
margin: 2em auto;
}
#results {
text-align: center;
}
</style>
<script type='text/javascript'>
//<![CDATA[
$(function () {
var index = 1;
$(".draggable").draggable({
containment: "parent",
});
$('#btn_add').click(function () {
var pointID = "Point" + (index++);
var top = Math.floor(Math.random() * 501);
var left = Math.floor(Math.random() * 401);
drawPoint(pointID, top, left);
});
$('#btn_getCoord').click(function () {
writeCoordination();
});
$('#btn_erase').click(function () {
eraseAllPoint();
writeCoordination();
});
function drawPoint(pointId, top, left) {
var htmlData = $('<div class="draggable" id=' + pointId + '>' + pointId + '</div>');
htmlData.css({ 'left': top + 'px', 'top': left + 'px' });
$('.canvas').append(htmlData);
$(".draggable").draggable({ containment: "parent" });
}
function writeCoordination() {
var output = '-Coordination-';
$('.draggable').each(function () {
output += '<br />' + $(this).attr("id") + ' => x: ' + $(this).position().left + ', y: ' + $(this).position().top;
});
$('#results').html(output);
}
function eraseAllPoint() {
$('.canvas').html('');
}
});
//]]>
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="canvas">
<div class="draggable" id="Point0">Point0</div>
</div>
<div id="results">coordination</div>
<input type='button' id="btn_add" value='Add box' />
<input type='button' id="btn_getCoord" value="Get Coornination" />
<input type='button' id="btn_erase" value='Erase All' />
<asp:Button ID="btn_submit" runat="server" Text="Upload" />
</form>
</body>
</html>