Register Javascript at the bottom of the page

It's a good idea to instantiate your javascript on the module where it occurs. This keeps everything together and also the js code isn't running on pages where the module doesn't exist. This will also ensure that your module will work, even when toggling the Theme in the CMS(TODO:link).


Found in : AdvantageCommonBasePage, AdvantageModule

The easiest method is to wrap your script in an asp literal, and register it from code behind.

RegisterBottomScript will place your code at the very end of the page. 


<asp:Literal runat="server" id="litJavascript">


protected void Page_Load(object sender, EventArgs e)


If you need to use server tags, you won't be able to add them into a literal. Use this method instead.

From code behind, we grab the div and inject it into the content placeholder at the bottom of the page.

<div runat="server" id="divBottomJavascript">


private void InjectJavascriptIntoContentPlaceHolder()
	var master = Page.Master.Master ?? Page.Master;
    ContentPlaceHolder bottomJavascriptContent = master.FindControl("BottomJavascriptContent") as ContentPlaceHolder;
    HtmlGenericControl divBottomJavascript = this.FindControl("divBottomJavascript") as HtmlGenericControl;
    if (bottomJavascriptContent != null && divBottomJavascript != null)
protected void Page_Load(object sender, EventArgs e)


Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request