Noble Bell


I have a set of points saved in an array. (I wrote this in JavaScript). My question is how can I save that point array to a file on the server so that I can use it elsewhere on the server like in asp.net or c#

Thanks,

nb





Re: How can I save a javascript array of points to a file on the server so I can use it elsewhere on the server like in C#?

Derek Chan


What you could do is to transfer your points into an asp.net textbox (which would be an <input> tag in html) using document.getElementbyID("txtArray") where txtArray is the ID of your input tag and then in your code behind when an event is triggered (say a button is clicked) then you would grab the txtArray.Text and parse it out as well as execute any logic needed on it.

Hope that helps start things off,






Re: How can I save a javascript array of points to a file on the server so I can use it elsewhere on the server like in C#?

SoulSolutions

The answer is dependant on whether you use asp.net AJAX. If you do then it is rather simple:

  1. Create a web service that accepts an array of VELatLong (have to define the class in C#) and then saves it out to a database with whatever server side logic you like (agaists a username, selected a colour and line width etc)
  2. Expose this web service to the client javascript by adding the [ScriptService] tag to the service and [ScriptMethod] to this method.
  3. Add the service to your scriptmanager
  4. Now you can call the webservice in javascript passing the data

http://ajax.asp.net/docs/tutorials/ASPNETAJAXWebServicesTutorials.aspx

If your not using MS AJAX the you still use normal AJAX but call a page like update.aspx again passing the data.

I actually encode my set of point to reduce the amount of data and also it makes it a simple string rather then an array of objects:

http://www.soulsolutions.com.au/Articles/Encodingforperformance/tabid/96/Default.aspx

pass the array of VElatlong to the javascript encode function and then use the c# decode to break it back out to a list of VELatLong.

John.








Re: How can I save a javascript array of points to a file on the server so I can use it elsewhere on the server like in C#?

Noble Bell

Wow! Thanks. You all have given me some good starting points. I thought it would be a little more simple than this though. I just wanted to take a Javascript variable and place it into an asp.net variable so that I can save it to a file on the server via asp.net.

I am not that up-to-speed on Internet and Web programming so I will have to dig into this stuff a little more. I will look into this stuff, it sounds pretty interesting.

Thanks,

nb






Re: How can I save a javascript array of points to a file on the server so I can use it elsewhere on the server like in C#?

Smuts

John,
I'm not using AJAX and your article on encoding was great, but I wonder, how do I pass the data to the update.aspx page. If if was the same page I would have used a hiddenfield to pass the data from client JavaScript to server-side C#, but to another page... Well, after encoding, perhaps add it the the page's querystring, or what
/Smuts




Re: How can I save a javascript array of points to a file on the server so I can use it elsewhere on the server like in C#?

Noble Bell

Call me stupid because I have not done this stuff in quite sometime, but how do I get my points that I have clicked on in the Virtual Earth Map to appear in the textbox that I added to the page with the input tag

I think that I would use this

Code Snippet

document.getElementById("txtLatLong").value = latlong;

nb






Re: How can I save a javascript array of points to a file on the server so I can use it elsewhere on the server like in C#?

Derek Chan

Noble Bell wrote:

Call me stupid because I have not done this stuff in quite sometime, but how do I get my points that I have clicked on in the Virtual Earth Map to appear in the textbox that I added to the page with the input tag

I think that I would use this

Code Snippet

document.getElementById("txtLatLong").value = latlong;

nb



Nb,


this ones not as trivial as it seems, but basically you need to attach an eventhandler such that when the map is clicked, it fills the input tag with the latlong they had clicked on. Some sample code below:

Code Snippet
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js"></script>
; <link rel="stylesheet" type="text/css" href="pins.css">
<script>
var map;

function MyOnload()
{
map = new VEMap('mymap');
map.LoadMap();
map.AttachEvent('onclick', myEventTester); //change to your event
}
function myEventTester(e)
{
var events = "mapstyle: " + e.view.mapStyle;
events +="<br/>latlong: " + e.view.latlong.latitude + ", " + e.view.latlong.longitude;
events +="<br/>LatLong: " + e.view.LatLong;
document.getElementById("txtLatLong").value = e.view.LatLong;
events +="<br/>zoomLevel: " + e.view.zoomLevel;
events +="<br/>sceneID: " + e.view.sceneId;
events +="<br/>sceneOrientation: " + e.view.sceneOrientation;

document.getElementById('events').innerHTML = events;
}
</script>
</head>
<body onload="MyOnload()">
<div id='mymap' style="position:relative; width:600px; height:400px;"></div>
<div id='events' style="position:relative; width:600px; height:400px;"></div>
<INPUT id='txtLatLong' type='text'>
</body>
</html>

You should see a textbox on the bottom of the screen populate with latlongs when you click on the map. I basically modified the SDK sample at: http://dev.live.com/virtualearth/sdk/ref/HTML/Ev_Namespace_VEMap_onmousedown.htm

Hope that helps,