Dynamic UL/LI ASP.NET + colapse Javascript
I am creating controls which are added to the page at run time. As these controls are added I separate them into a UL/LI list by injecting literals assigned as (<ul>, </ul>,<li>,</li>). The page in question uses a master page template. The ul/li function is called in the page_load event of the child page.
I want to assign a script that collapses this list. How do I apply the script so that it will fire after all the dynamic controls have been created and added.
I've tried
<body onload = >
sPage.ClientScript.RegisterStartupScript(Me.GetType, "MyFunction", "setvisibility();", True)
jasystweb
Newbie Poster
9 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
I am creating controls which are added to the page at run time. As these controls are added I separate them into a UL/LI list by injecting literals assigned as (<ul>, </ul>,<li>,</li>). The page in question uses a master page template. The ul/li function is called in the page_load event of the child page.
I want to assign a script that collapses this list. How do I apply the script so that it will fire after all the dynamic controls have been created and added.
I've tried
<body onload = >
sPage.ClientScript.RegisterStartupScript(Me.GetType, "MyFunction", "setvisibility();", True)
The bad thing with onload is that it's called before everything is actually drawed in the page, jQuery have fixed this issue. Write this up in the header script.
<script type="text/javascript">
$(document).ready(function() {
sPage.ClientScript.RegisterStartupScript(Me.GetType, "MyFunction", "setvisibility();", True)
});
</script>
PierlucSS
Junior Poster
188 posts since Feb 2010
Reputation Points: 65
Solved Threads: 31
Skill Endorsements: 0
This has not resolved the issue. Whenever this script fires it returns null on the dynamically generated UL/LI tags as when the script tries to 'getELementbyID.' --I guess the tags STILL have not been created created by the time the script fires.
The class which creates the ul/li list is fired from the page_load event in ASP. the ClientScript.RegisterStartupScript is added in the same page load following the ul/li class creator.
All I want is for my asp code to dynamically generate a UL/LI list and then use java script to collapse it on the client-side. How do set a script to fire off after EVERYTHING has been generated. I assume I have to add the script after page_load.
jasystweb
Newbie Poster
9 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
I read up a bit on the page life cycle here. MSDN
I have placed the function that creates the controls in page_init. I add the java script during the page load. So far this seems as if this is solution to my problem.
Page_Init
'//my function that creates the li/ul tags and applies them to a panel
Dim sf as new clLayout
sf.createlayout(spanel)
Page_Load
ClientScript.RegisterStartupScript(Me.GetType, "MyFunction", "setvisibility();", True)
jasystweb
Newbie Poster
9 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 3 Years Ago by
PierlucSS