1: public static void AddScriptFile(string File,string Directory)
2: {
3: System.Web.UI.Page CurrentPage = (System.Web.UI.Page)HttpContext.Current.CurrentHandler;
4: bool Added = false;
5:
6: foreach (Control CurrentControl in CurrentPage.Header.Controls)
7: {
8: if (CurrentControl.GetType() == typeof(HtmlGenericControl))
9: {
10: HtmlGenericControl HTMLGenericControl = (HtmlGenericControl)CurrentControl;
11: if (HTMLGenericControl.Attributes["src"] != null)
12: {
13: if (HTMLGenericControl.Attributes["src"].Contains(File))
14: {
15: Added = true;
16: }
17: }
18: }
19: }
20:
21: if (!Added)
22: {
23: HtmlGenericControl ScriptControl = new HtmlGenericControl("script");
24: ScriptControl.Attributes.Add("type", "text/javascript");
25: ScriptControl.Attributes.Add("src", Directory + File);
26:
27: CurrentPage.Header.Controls.Add(ScriptControl);
28: }
29: }