0
下面是我的vb.net代碼如何從ASP代碼後面調用JavaScript函數?
ClientScript.RegisterStartupScript([GetType](), Guid.NewGuid().ToString(), "javascript:MarkerFunction('" & dt.Rows(i)("vehno") & "','" & dt.Rows(i)("trackdt") & "','" & Lat & "','" & Lon & "','" & VehImage & "','" & dt.Rows(i)("City") & "','" & dt.Rows(i)("Speed") & "');", True)
而下面是我JavaScript Function
<script type="text/javascript">
function init()
{
map = new OpenLayers.Map("basicMap");
var mapnik = new OpenLayers.Layer.OSM();
var fromProjection = new OpenLayers.Projection("EPSG:4326"); // Transform from WGS 1984
var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
var position = new OpenLayers.LonLat(78.0000,21.0000).transform(fromProjection, toProjection);
var zoom = 5;
map.addLayer(mapnik);
map.setCenter(position, zoom);
var vectorLayer = new OpenLayers.Layer.Vector("Overlay");
function MarkerFunction(VehNo,Trackdt,Lat,Lon,VehImage,City,Speed)
{
alert('hii');
var feature = new OpenLayers.Feature.Vector
(
new OpenLayers.Geometry.Point(lon, lat).transform(fromProjection, toProjection),
{description: 'Vehicle No : ' + VehNo+'<br>Track Date : ' + Trackdt +'<br> City : '+ City + '<br> Speed : '+ Speed } ,
{externalGraphic: VehImage, graphicHeight: 25, graphicWidth: 21, graphicXOffset:-12, graphicYOffset:-25 }
);
vectorLayer.addFeatures(feature);
}
//Add a selector control to the vectorLayer with popup functions
var controls =
{
selector: new OpenLayers.Control.SelectFeature(vectorLayer, { onSelect: createPopup, onUnselect: destroyPopup })
};
function createPopup(feature)
{
feature.popup = new OpenLayers.Popup.FramedCloud("pop",
feature.geometry.getBounds().getCenterLonLat(),
null,
'<div class="markerContent">'+feature.attributes.description+'</div>',
null,
true,
function() { controls['selector'].unselectAll(); }
);
map.addPopup(feature.popup);
}
function destroyPopup(feature)
{
feature.popup.destroy();
feature.popup = null;
}
map.addControl(controls['selector']);
controls['selector'].activate();
map.addLayer(vectorLayer);
}
</script>
<body onload="init()">
<div id="basicMap">
</div>
</body>
我想打電話從隱藏文件的代碼MarkerFunction
但我無法調用它。 我嘗試了一切,但我不知道我的代碼有什麼問題。 任何幫助將不勝感激。在此先感謝...
你不能從服務器代碼執行JS腳本。你可以使用AJAX/WebSockets等的組合來進行通信。但是這對你來說已經超出了範圍。您需要幾個星期才能開始使用該程序 –