VDS Technologies

 

How to stop postback after mouse move

7/1/2013 2:54:35 PM
Total Posts 2

How to stop postback after mouse move

I want to be able to draw a rectangle on the map and save the start and end coords, but as soon as the mouseup event on the browser happens, the map posts back and refreshes the page, so I lose my coordinates. How can I stop the postback, or am I doing something wrong? Here is my code - which seems pretty simple:

<body>
<form id="Form1" method="post" runat="server">
<aspmap:Map ID="map" runat="server" Height="400px" Width="750px" BackColor="#FFFFFF"
ImageFormat="Gif" ></aspmap:Map>
<br>
<span id="StartPos"></span>
<br>
<span id="EndPos"></span><script>

var map = AspMap.find('<%=map.ClientID%>');
map.set_mapTool(AspMap.MapTool.Rectangle);
map.add_mouseMove(mouseMoveHandler);

function mouseMoveHandler(sender, e) {
    var label = document.getElementById("latlong");
    if (mouseDown == 1) {

        if (dragging == 0) {
            label = document.getElementById("StartPos");
            label.innerHTML = "Start: Latitude: " + e.latitude + " | Longitude: " + e.longitude;
        }
        dragging = 1;
    }
    if (dragging == 1) {
        label = document.getElementById("EndPos");
        label.innerHTML = "End: Latitude: " + e.latitude + " | Longitude: " + e.longitude;
    }
}

var mouseDown = 0;

var dragging = 0;

document.body.onmousedown = function () {
    mouseDown = 1;
    dragging = 0
}

document.body.onmouseup = function () {
    mouseDown = 0;
    dragging = 0
}
</script>

</form>
</body>

7/2/2013 12:45:03 AM
MVP
Total Posts 323

Re: How to stop postback after mouse move

The Rectangle tool always sends the coordinates of the rectangle to the server.
Place the Map control into an UpdatePanel to refresh the Map control only.

7/2/2013 5:21:39 AM
Total Posts 2

Re: How to stop postback after mouse move

But what if I don't want the map to refresh? I simply want to drag a rectangle over it and display the rectangle coordinates in form fields - I don't even need the rectangle to stay on the map.

Thanks for your help.