ClientScriptManager…why didn’t that work

NET 2.0 added the ClientScriptManager to allow developers a simple method to add javascript and other "Script" capabilites to a web page easily.  However, the documentation never really got developed, so attempting to use it can be a bit trick.

Lets start with adding an include of a .js file.


override void Render(HtmlTextWriter writer)
if (!this.Page.ClientScript.IsClientScriptIncludeRegistered(this.GetType(), VirtualEarthSettings
this.Page.ClientScript.RegisterClientScriptInclude(this.GetType(), VirtualEarthSettings.VirtualEarthJScriptTagHeader,

Didn’t work did it? 

You can’t call RegisterClientScriptInclude(…) after the PreRender section of the page lifecycle.  Best bet: call in OnInit.
In fact about the ONLY ClientScriptManager function you can use after the PreRender is: ClientScript.RegisterStartupScript

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s