Problem getting array values into Java Script from code behind file

  • Thread starter Thread starter Tenacious
  • Start date Start date
T

Tenacious

I find that I can call a function in my code behind file from Java
Script on the aspx page using this syntax:
Lat = <%= GetNextLatitude()%>

The function has to be static. No problem so far. When I put the
function in a for loop like so:
for(var i = 0; i < TotalPoints; i++)
{
Lat = <%= GetNextLatitude()%>
Lng = <%= GetNextLongitude()%>
LatLngPoints[cnt] = new GLatLng(Lat, Lng);
}

the return value from the function stays the same for each iteration
of the loop. Using the debugger I can tell that even if TotalPoints is
1000, the function in reality only gets called once. I can call it
more than once if it is not from a loop. Why does this happen? Is
there any other way that I can get an array from the code behind page
to the Java Script in the client?

Thanks
 
your server function are called during render of the html not when the
browser runs the javascript, so they are only called once (do a view
source). see ClientScriptManager.RegisterArrayDeclaration().


-- bruce (sqlwork.com)
 
StringBuilder latLongs = new StringBuilder(");
for (int i = 0; i < TotalPoints; i++)
{
latLongs.Append("new GtLatLng(GetNextLatitude().ToString() + "," +
GetNextLongitude().ToString() + ")");
if (i < TotalPoints - 1) latLongs.AppendLine(",");
}
Page.ClientScript.RegisterArrayDeclaration("LatLongPoints",
latLongs.ToString());

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
StringBuilder latLongs = new StringBuilder(");
for (int i = 0; i < TotalPoints; i++)
{
latLongs.Append("new GtLatLng(GetNextLatitude().ToString() + "," +
GetNextLongitude().ToString() + ")");
if (i < TotalPoints - 1) latLongs.AppendLine(",");}

Page.ClientScript.RegisterArrayDeclaration("LatLongPoints",
latLongs.ToString());

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:http://www.miradyne.net




I find that I can call a function in my code behind file from Java
Script on the aspx page using this syntax:
Lat = <%= GetNextLatitude()%>
The function has to be static. No problem so far. When I put the
function in a for loop like so:
for(var i = 0; i < TotalPoints; i++)
{
Lat = <%= GetNextLatitude()%>
Lng = <%= GetNextLongitude()%>
LatLngPoints[cnt] = new GLatLng(Lat, Lng);
}
the return value from the function stays the same for each iteration
of the loop. Using the debugger I can tell that even if TotalPoints is
1000, the function in reality only gets called once. I can call it
more than once if it is not from a loop. Why does this happen? Is
there any other way that I can get an array from the code behind page
to the Java Script in the client?
Thanks- Hide quoted text -

- Show quoted text -

Thanks for the help. It pointed me in the right direction and got me
over this hurdle.
 
Back
Top