Javascript array variable in C#

asp.net , csharp , java , javascript Philadelphia, United States
  • 12 years ago

    hi

    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 %>"

    </script>

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

     

    thanks

     

    sanjeev

     

     

     

  • 12 years ago

    How about something like:

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

     

    Joe 

Post a reply

Enter your message below

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

Contribute

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