How to read something from a C # file and use it with HTML codes on an ASP.NET page?

I’m doing a school project, I need to make a simple website, add Google maps to it, read, say, 100 different addresses from a text file and show these locations on Google maps using markers.

Now I am trying to add google maps to an ASP.net page using javascript, which I saw in Google map tutorials. And there is this problem that I have to convert the addresses to coordinates. Therefore, for this I use

function addAddressToMap(response) { if (!response || response.Status.code != 200) { alert("Sorry, we were unable to geocode that address"); } else { place = response.Placemark[0]; point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]); marker = new GMarker(point); map.addOverlay(marker); marker.openInfoWindowHtml(place.address + '<br>' + '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode); } } // showLocation() is called when you click on the Search button // in the form. It geocodes the address entered into the form // and adds a marker to the map at that location. function showLocation() { var address = "izmit"; var address2 = "ağrı"; geocoder.getLocations(address, addAddressToMap); geocoder.getLocations(address2, addAddressToMap); } 

these functions, and they work fine. But my problem here is that I need to get this address data from a text file. But in order to get them, I need to use several different codes. And I want to do this server side with C # codes. But I do not know how to write codes on the server side, and then return something on the HTML side as an address. I hope you understand. Thanks for the help.

Update:

 Server code: public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Page.ClientScript.RegisterArrayDeclaration("Skills", "'asa'"); Page.ClientScript.RegisterArrayDeclaration("Skills", "'bell'"); Page.ClientScript.RegisterArrayDeclaration("Skills", "'C'"); Page.ClientScript.RegisterArrayDeclaration("Skills", "'C++'"); } } Client side: function showLocation() { var address = "izmit"; var address2 = "ağrı"; geocoder.getLocations(Skills[0], addAddressToMap); } 

Now, if I use "asa" instead of Skills [0], it will show the location and mark, but with skills [0] it does not work. And thanks for your reply, this is what I am looking for.

even if I try var MyValue = Skills [0]; and then use MyValue instead of Skills [0], it still doesn't work

+4
source share
1 answer

If I understand your question correctly, you want to create an array on the server side and read it on the client.

See this link for guidance on transferring an array from the server to the client.

Basically, you want to use the ClientScriptManager.RegisterArrayDeclaration method to add values ​​to the array.

Then you can read it easily in javascript.

Server side:

 string arrayName = "MyArray"; Page.ClientScript.RegisterArrayDeclaration(arrayName , "'value1'"); Page.ClientScript.RegisterArrayDeclaration(arrayName , "'value2'"); 

Client Side Javascript:

 function readArray() { for (var i = 0; i < MyArray.length; i++) { //Reading Element From Array var myValue = MyArray[i]; } } 
+1
source

Source: https://habr.com/ru/post/1441503/


All Articles