Click here to Skip to main content
14,640,713 members
Rate this:
Please Sign up or sign in to vote.
Hi,
I have a javascript function in a for loop. i call this function from code behind file. but the function is only called once even if loop has two iterations. here is the code.

 for (int i = 0; i < nodes; i++)
 {
ClientScript.RegisterStartupScript(Page.GetType(), "abc", "func('" + xPosition + "','" + yPosition + "','"+nodes+"');", true);

 }


Function:
function func(xPosition, yPosition, nodes)
     {
         alert(nodes);
             svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
             //            svg.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
             //            svg.setAttribute('version', '1.1');
             svg.setAttribute('width', '4cm');
             svg.setAttribute('height', '2cm');
             svg.setAttribute('x', xPosition);
             svg.setAttribute('y', yPosition);
             mainSvg.appendChild(svg);
             //alert(xPosition + '","' + yPosition);


             rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
             rect.setAttribute("id", "myrect");
             rect.setAttribute("fill", "red");
             rect.setAttribute("stroke", "black");
             rect.setAttribute("stroke-width", "2");
             rect.setAttribute("x", 5);
             rect.setAttribute("y", 5);
             rect.setAttribute("width", "150");
             rect.setAttribute("height", "50");
             document.body.appendChild(rect);
             svg.appendChild(rect);


     }



I shall be thankful for you help.
Usama Javed
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

You can't registering the same type/key combination more than once. By setting different key you can able to use RegisterStatupScript more than once
   
v2
Comments
osama.javed 6-May-13 7:47am
   
Thankyou so much sir.
Joezer BH 6-May-13 7:54am
   
5ed!
Shubhashish_Mandal 6-May-13 8:52am
   
welcome :)
Shubhashish_Mandal 6-May-13 8:52am
   
Thanks Edo
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hello Osama,

You have a serious problem with the line containing this:
func('" + xPosition + "','" + yPosition + "','"+nodes+"')

You are trying to register the same function many times, which of course is not allowed.

Cheers,
Edo
   
v2

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