Пример #1
0
        private void BuildChildControl(string scriptUrl, ScriptPositionMode mode)
        {
            switch (mode)
            {
                case ScriptPositionMode.Header:
                    HtmlGenericControl ctr = new HtmlGenericControl("script");
                    ctr.Attributes.Add("language", "javascript");
                    ctr.Attributes.Add("type", "text/javascript");
                    ctr.Attributes.Add("src", ctr.ResolveUrl(scriptUrl));
                    this.Controls.Add(ctr);
                    break;

                case ScriptPositionMode.ScriptManager:
                    ScriptManager sm = ScriptManager.GetCurrent(this.Page);

                    ExceptionHelper.TrueThrow(sm == null, Resources.DeluxeWebResource.E_NoScriptManager);

                    sm.Scripts.Add(new ScriptReference(scriptUrl));
                    break;

                case ScriptPositionMode.BodyStart:
                    this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), Guid.NewGuid().ToString(),
                        string.Format(_C_SCRIPT_FORMAT, scriptUrl), false);
                    break;

                case ScriptPositionMode.BodyEnd:
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(),
                        string.Format(_C_SCRIPT_FORMAT, scriptUrl), false);
                    break;

            }
        }
Пример #2
0
 public HtmlGenericControl CreateJavaScriptLink(string scriptFilePath, string Tip = "")
 {
     var script = new HtmlGenericControl();
     script.TagName = "script";
     if (Tip != "")
     {
         script.Attributes.Add("type", "text/javascript");
     }
     script.Attributes.Add("src", script.ResolveUrl(scriptFilePath));
     return script;
 }