I'm a beginner of C#.
Question: I'm trying to retrieve a variable area
from Javascript function compute_shape_area()
, how do I implement in C# asp.net? Thanks a lot.
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body onload="compute_shape_area()">
<p id="area1"></p>
<script>
var Obj_shape;
function initMap() {
var request = new XMLHttpRequest();
request.open('GET', 'http://localhost:8080/shape.txt');
//GET Data and build Obj_shape
request.send();
}
function compute_shape_area(){
var area = parseFloat(google.maps.geometry.spherical.computeArea(Obj_shape.getPath()));
area = area.toFixed(4);
document.getElementById("area1").innerHTML = area;
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=APIKey&callback=initMap"></script>
</body>
</html>
You could use an asp:HiddenField
variables to share values between code behind in C# and your JavaScript code (viewstateapproch during postbacks).
Or you could use the following code:
<script type="text/javascript"> var yourJsVariable= '<%=yourJsVariable%>'</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.