Problem getting array values into Java Script from code behind file

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
 
B

bruce barker

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)
 
K

Kevin Spencer

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
 
T

Tenacious

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top