views:

34

answers:

1

I have a problem that when i bring the array of asp and use it in the javascript, When i use the counter (i++) and print for each index of array just like "<%=app[i] %>" and it is not return the value back to me. Please help me i solve this problem for a day !!!-Thanks ^_^

edit

 <%
    String[] asp = {"a","b","c"};

     %>
      <script language="javascript">

      for(var i=0;i<"<%=asp %>".length;i++){
      document.write("<%=asp[i] %>")

      }
      </script>

the error is = Compiler Error Message: CS0103: The name 'i' does not exist in the current context

A: 

ASP runs on the server, Javascript in the browser. The ASP parts are first evaluated on the server side, which results in this:

  <script language="javascript">
  for(var i=0;i<"Array".length;i++){
      document.write("< i is not defined here because ASP doesn't care about the Javascript part >")
  }
  </script>

This would be send to the browser, where the Javascript would be evaluated.

Either loop in ASP or loop in Javascript. Both don't run at the same time and hence don't mix.

deceze