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)

Recommended Answers

All 3 Replies

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>

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.

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)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.