473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Problem getting array values into Java Script from code behind file

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

Apr 25 '07 #1
3 5408
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)
Tenacious wrote:
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
Apr 26 '07 #2
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("LatLon gPoints",
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
"Tenacious" <CT*******@yahoo.comwrote in message
news:11*********************@u32g2000prd.googlegro ups.com...
>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

Apr 26 '07 #3
On Apr 26, 3:59 am, "Kevin Spencer" <unclechut...@nothinks.comwrote:
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("LatLon gPoints",
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

"Tenacious" <CT_Tay...@yahoo.comwrote in message

news:11*********************@u32g2000prd.googlegro ups.com...
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.

Apr 27 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: CeNo | last post by:
All, Any help would be appriecated here...I have downloaded a working script, for use with a web site of images. The java is a slide show of images....Anyways, the images dont load in the slide...
8
by: rdlebreton | last post by:
Hi, Folks! I've been trying to develop my own version of these draggable layers and I have been limiting myself to IE6...for now. I have looked at some other examples to get ideas of creating...
8
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to...
9
by: Morten | last post by:
Hi! I have a problem displaying some values in a datagrid. I have an array that consists of a number of objects. Each object has 2 properties: Name and a list of web addresses. (e.g: Name:...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
10
by: Cainnech | last post by:
Hi guys, I'm a bit puzzled by a script I'm trying to write. I'm doing a script which wil automatically generates a series of commands which can then be executed by a third party application. Very...
2
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double)...
4
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
1
by: sheldonlg | last post by:
I have inherited code with a TDC control. In this file, there are two javascripts of interest. One of these is a function, filter(), which is inside <script language=javascript></script>. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.