ASP.net: Add a Javascript tag to the HEAD of the page.


/ Published in: C#
Save to your folder(s)

Call with the path of any javascript you want to load into the HEAD of the ASPX page.


Copy this code and paste it in your HTML
  1. /// <summary>
  2. /// Registers the client script include.
  3. /// </summary>
  4. /// <param name="src">The file name.</param>
  5. void RegisterClientScriptInclude(string src)
  6. {
  7. System.Web.UI.HtmlControls.HtmlGenericControl si = new System.Web.UI.HtmlControls.HtmlGenericControl();
  8. si.TagName = "script";
  9. si.Attributes.Add("type", "text/javascript");
  10. si.Attributes.Add("src", src);
  11. this.Page.Header.Controls.Add(si);
  12. this.Page.Header.Controls.Add(new LiteralControl("\n"));
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.