Click here to Skip to main content
15,935,259 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi all
I wanna bypass array of string to the client side code ( javascript) as follow :

protected void Page_Load(object sender, EventArgs e)
           string[] chi = { "sara","mathew" };

           Page.ClientScript.RegisterArrayDeclaration("chi", chi.ToString());

and in client code :

<script type="text/javascript">  
function pp()
                var iChi = new Array(10);
                for (var i = 0; i <chi.length; i++) {
            catch (Err) {


but i can't access to the chip that defined in code behind in above script.

What I have tried:

when call array in the javascript don't identify array that define on it.
Updated 18-Jun-16 6:03am
Sergey Alexandrovich Kryukov 18-Jun-16 13:50pm    
You never ever call JavaScript from the server side. Just think about it: code behind is on the server side, and JavaScript is on the client side. You only pass data from server-side indirectly, by generating content, including JavaScript code, in your HTTP response. This is actually the whole purpose of ASP.NET. In particular, you can include some JavaScript in your ASP.NET file, and use, for example, Razor syntax @{...} (or whatever you use) to write some fragment of JavaScript code calculated out of your server-side data.

bernova 18-Jun-16 14:31pm    
how do i use chi array in javascript ?! , what have solution ?!!
for example :

just i change it to array
an0ther1 19-Jun-16 21:35pm    
Not sure why you are doing this but anyway..
Assuming you have a hidden field on your ASP page that you are populating on the server then you could populate the field with your text & delimit it with a character unlikely to be used in the text - below I have used a ";" character
eg: sara;matthew
Then on the client side, use;
var objText = document.getElementById('<%=HiddenfieldId.ClientID%>');
var objArray = objText.split(";");

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