From: "Chris Jackson" <chrisjATmvpsDOTorgNOSPAM>
References: <
[email protected]>
Subject: Re: Pass ASP Array variable to Javascript
Date: Thu, 6 Nov 2003 15:58:41 -0500
Lines: 55
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <
[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 208.252.52.2
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:189110
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
What ASP.NET sends to the browser is plain text, not objects. You need to
keep in mind that you have two different programming models - one on the
server, and one on the client. If you aren't writing the text for the client
side on the server-side code, then the client isn't getting it. The code you
display here assumes that the client can, in some way, communicate with the
server and get that variable, and that this variable will be type
compatible. Neither assumption is true.
Instead, you need your server side code to write out the code to initialize
this array. Instead of just databinding to the array type, you'll have to
iterate through the array and write it all out:
(my vbscript skills are very rusty, so don't type this in directly, but you
get the idea...)
var x = new Array(10);
<%
dim i
for i = 0 to Len(myArrayAsp) - 1
' Assumes 0-based on client and 1-based on server
Response.Write "x[" & i & "] = " & myArrayAsp(i + 1) & ";"
next i
%>
--
Chris Jackson
Software Engineer
Microsoft MVP - Windows XP
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--
Augusto Cesar said:
Hello people.
How can I Pass ASP Array variable to Javascript;
I´m to trying this:
<script language="JavaScript">
var x = new Array(10);
x = <%= myArrayAsp %>;
</script>
but return error to me...