0

I have worked about Google Maps Javascript API I have an issue.

In my js code

        var RX1 = [];
        var RY1 = [];
        var RX2 = [];
        var RY2 = [];
        var i;
        try
        {
            for (i = 0; i < RRCount; i++)
            {
                RX1[i] = <%=ListBoxRX1.Items[i] %>;
                RY1[i] = <%=ListBoxRY1.Items[i] %>;
                RX2[i] = <%=ListBoxRX2.Items[i] %>;
                RY2[i] = <%=ListBoxRY2.Items[i] %>;
            }
        }
        catch (e)
        {
            alert("MSSQL 403 Hatası !! Forbidden.");
        }

in this code ListBoxRX1.Items[i] i variable error is "The name 'i' does not exist in the current context"

I did everything but I didn't have found. Please help! Thanks a lot.

4
  • The problem is, that the javascript code is executed on the client, whereas your ListBox code is executed on server side. That means, that at the point of accessing the ListBox items (on the server) i is not defined. Commented Mar 26, 2018 at 21:07
  • You might take a look at this post: stackoverflow.com/a/3465192/9487478 Commented Mar 26, 2018 at 21:13
  • thx I will check this. Commented Mar 26, 2018 at 21:26
  • I finished this issue Thanks for all of it :) Commented Mar 27, 2018 at 9:51

1 Answer 1

0

The issue is that "i" and the for loop are declared in the JavaScript, not in ASP.NET, and as a result they are not accessible to the code running on the server and the loop does not execute on the server. You will need to have your loop run on the server, using something like this (assuming RRCount is a server side variable):

    var RX1 = [];
    var RY1 = [];
    var RX2 = [];
    var RY2 = [];
    var i;
    try
    {
        <% 
        for (int i = 0; i < RRCount; i++) 
        { 
        %>
            <%="RX1[" + i + "] = '" + ListBoxRX1.Items[i] + '";" %>
            <%="RY1[" + i + "] = '" + ListBoxRY1.Items[i] + '";" %>
            <%="RX2[" + i + "] = '" + ListBoxRX2.Items[i] + '";" %>
            <%="RY2[" + i + "] = '" + ListBoxRY2.Items[i] + '";" %>
        <% 
        }  
        %>
    }
    catch (e)
    {
        alert("MSSQL 403 Hatası !! Forbidden.");
    }
Sign up to request clarification or add additional context in comments.

4 Comments

I tried this thanks but it didn't work. Variables still get same error.
That's because "i" is still not declared. Use for (int i = 0; i < RRCount; i++).
Thanks for your advice Paul Pearce. I have fixed that from other Paul brother :))
Hi @SerkanKaya if this answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.