Posted By

jink on 05/20/09


Tagged

javascript load head aspnet


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

umang_nine
emregulcan


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


 / Published in: C#
 

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

  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  

You need to login to post a comment.