Problem accessing server side array values from javascript client side function

i faced the following problem ..i have an array that store the values of a resultset row under the server side coding.How do i retrieve them under my client side javascript function.I wrote the following coding under my client side function and it got an error.BSCStr is an array storing data from a resultset row which i did under the server side coding. 

From client side function:
addr=addr + "&C" + i + "=" + <%=BSCStr[i]%>;
0
wingshya
4/11/2004 12:44:21 PM
📁 asp.net.getting-started
📃 91979 articles.
⭐ 4 followers.

💬 1 Replies
👁️‍🗨️ 1483 Views


First of all, you can't mix server-side and client-side code. The reason is that the protocol that is used to communicate between client and server (i.e. HTTP) doesn't allow this.
Secondly, is this script in an external .js file or embedded in the Page itself? If it's embedded in the Page, then if you look at the source of the web page (in the menubar click on View -> Source) you will see (assuming BSCStr[i] == "test"):
    addr=addr + "&C" + i + "=" + test;
This means that the browser is expecting a variable named test to have been defined (which obviously hasn't been). If you surround the <%= ... %> with quotation marks, i.e.
    addr=addr + "&C" + i + "=" + "<%=BSCStr[i]%>";
you will see:
    addr=addr + "&C" + i + "=" + "test";
However, if i is defined on the client (which is what I suspect) then this won't work either. What you need to do is define an array in your JavaScript and then create a server-side loop that outputs a literal string that will, on the client, populate the array. For example:
    

This will result in the following:
    var BSCStr = new Array ( "test1", "test2", "test3" ); 
Finally, remove the "<%= " and "%>" from your original JavaScript.

Steven Bey

Recursion: see Recursion
0
stevenbey
4/11/2004 4:36:17 PM