Рow to get the array in HTML file added from some side initialize in .cs file? Hope for your reply.
            Asked
            
        
        
            Active
            
        
            Viewed 319 times
        
    2 Answers
1
            Your question does not provide enough info. I will assume you mean the codebehind file (c#) when you say .cs file (what else is there to assume?) and your array is added in c#, which you want to access in js
Register your array as a string literal as script block
something like:
string myArr = "; var myArr = [ 1, 2, 3, 4 ]; "; //putting your array in a string
ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), myArr, true);
now in your html file, you can access them with javascript.
<script type="text/javascript">
 alert(myArr[2]); //will alert 3
</script>
For 2D arrays,
var myArr = [[0,0],[1,1],[2,2]]; //2D array
alert(myArr[0]); //    to access 1st row: [0,0]
alert(myArr[0][0]); // to access 1st row 1st column: 0
 
    
    
        iamserious
        
- 5,385
- 12
- 41
- 60
- 
                    Thanks for your reply u are right that it is a c# .cs code behind file and my array name "string terms" its 2D array then it would be as same as you mentioned above? – Forums Forall Jul 07 '11 at 09:51
- 
                    Hi @Forums Forall, please look at the edit. It's exactly the same way, though the access will be slightly different. – iamserious Jul 07 '11 at 10:11
0
            
            
        - Send array (via GET) as comma separated list, e.g. Static.html?arr=1,2,3,4
- Read query string using JavaScript, e.g. jQuery Query Object
- Parse it into an array, e.g. string.split()
 
    
    
        Community
        
- 1
- 1
 
    
    
        abatishchev
        
- 98,240
- 88
- 296
- 433
