Click here to Skip to main content
14,638,959 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi, i am calling a JavaScript function from .cs file using Page.Client Script.RegisterStartupScript() function in a for loop and as parameter i am passing the latitude and longitude for marking markers in map but at the last of loop it is showing only marker for first value only.

Plz Help me.

Thanks.
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Show your code; not all of it... just enough so we can get the idea.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Your script key must be same on each iteration so the script will be rendered only for the first time.

Try this:
for (int i = 0; i < 5; i++)
{
     string loadscript = "alert('" + i + "');";
     string scriptKey = "loadscript" + i.ToString();            
     Page.RegisterStartupScript(scriptKey, "<script language=javascript>"
                        +loadscript+"</script>");
}

Having different script keys in a loop is necessary.
:thumbsup:
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100