Click here to Skip to main content
15,890,399 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

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

 }


Function:
JavaScript
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

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
 
Share this answer
 
v2
Comments
osama.javed 6-May-13 7:47am    
Thankyou so much sir.
Shubhashish_Mandal 6-May-13 8:52am    
welcome :)
Joezer BH 6-May-13 7:54am    
5ed!
Shubhashish_Mandal 6-May-13 8:52am    
Thanks Edo
Hello Osama,

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

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

Cheers,
Edo
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900