Click here to Skip to main content
15,887,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
protected void btn_add_Click(object sender, EventArgs e)
{
Create_property prp = new Create_property();
prp.client_id = Session["id"].ToString();
prp.vehicle_id = ddl_vehicle.SelectedValue.ToString();
prp.time = txt_hour.Text +":"+ txt_minit.Text+":00";
prp.time2 = txt_last_hour.Text +":"+ txt_last_minit.Text+":00";
string[] str = new string[2];
str = txt_date.Text.Split('-');
prp.date = str[2] + "/" + str[1] + "/" + str[0];
ds = Other_logic.display_plaback_map(prp);

-------create array here of data set record---------
}




C#
<script type="text/javascript">

function initialize() {
     var lat ="array value";
    var lon = "array value";
    var image= "~/Upload/Vehicle2091231993.jpg";
    var myLatlng = new google.maps.LatLng(lat, lon) // This is used to center the map to show our markers

    var mapOptions = {
        center: myLatlng,
        zoom: 15,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        marker: true
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    var marker = new google.maps.Marker({
        position: myLatlng
                 });
    marker.setMap(map);
}
    </script>




after create array in c# file than i want to pass array to java script and give one bye one array value to var lat and var longi
Posted

1 solution

SQL
to pass an array from server side to access it from client side we can use RegisterArrayDeclaration method.

Here is a simple example



In your code behind you can use the method like,


protected void Page_Load(object sender, EventArgs e)
{
RegisterArrayDeclaration("MyArray", "'Welcome'");
RegisterArrayDeclaration("MyArray", "'Hai'");
RegisterArrayDeclaration("MyArray", "'Hello'");
RegisterArrayDeclaration("MyArray", "'Best'");
RegisterArrayDeclaration("MyArray", "'Super'");
}



You can access this array from client side Javascript code,


C#
for (var i = 0; i < MyArray.length; i++) {
       alert(MyArray[i]);
}
 
Share this answer
 
Comments
Bama Boy 14-Sep-13 5:31am    
yes i used this but cant work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900