Javascript array variable in C# , csharp , java , javascript Philadelphia, United States
  • 12 years ago


    I am using javascript code in ASP.NET aspx page and using C# variable value to javascript variable as shown below :

    <script language="JavaScript1.2" type="text/javascript">

    var submenu=new Array()

    submenu[0] = "<%=Product[0] %>"

    submenu[1] = "<%=Product[1] %>"

    submenu[2] = "<%=Product[2] %>"

    submenu[3] = "<%=Product[3] %>"

    submenu[4] = "<%=Product[4] %>"

    submenu[5] = "<%=Product[5] %>"

    submenuDevil = "<%=ProductDevil %>"


    I want to convert this code in a loop. How can I convert it. Pls suggest.








  • 12 years ago

    How about something like:

    for (var x = 0; x <= 5; x++)
    submenu[x] = "<%=Product[x] %>";



Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Owning a computer without programming is like having a kitchen and using only the microwave oven” - Charles Petzold