Friday, July 6, 2012

c#,asp.net - Load javascript files from code behind/dynamically

Use a HtmlGenericControl in page_init of the webpage

protected void Page_Init(object sender, EventArgs e)
{
         HtmlGenericControl oDesktopJS = new HtmlGenericControl("script");
        oDesktopJS.Attributes.Add("type", "text/javascript");
        oDesktopJS.Attributes.Add("src", "https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js");
        Page.Header.Controls.Add(oDesktopJS);
}

No comments: