Rod Johnson
Rod Johnson

Reputation: 2427

Add external javascript to user control... but put the file reference at the bottom of the page

I need to be able to add an external js file for a user control (using

    this.Page.ClientScript.RegisterClientScriptInclude("SuggestionSearch", 
"~/Secure/Shared/SuggestionSearch.js");

syntax)

But it puts the javascript file on the page too early... is there a way to put the file at the bottom of the page?

Upvotes: 0

Views: 1531

Answers (1)

Denis Ivin
Denis Ivin

Reputation: 5644

Take a look at ClientScriptManager.RegisterStartupScript

Something like this could work:

ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "SuggestionSearch",
String.Format("<script src='{0}' type='text/javascript'></script>", ResolveUrl("~/Secure/Shared/SuggestionSearch.js")));

Upvotes: 2

Related Questions