Example #1
0
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            var manager  = PageModuleManager.Instance;
            var pageInfo = PageModuleManager.Get(this);

            if (manager != null && manager.HasControls)
            {
                if (!pageInfo._controlsAdded)
                {
                    foreach (var controlInfo in manager.Controls)
                    {
                        if (controlInfo.Type == ModuleControlType.Footer)
                        {
                            //if (source == null)
                            //    continue;
                            if (!string.IsNullOrEmpty(controlInfo.Path))
                            {
                                var control = this.Page.LoadControl(controlInfo.Path);
                                this.Controls.Add(control);
                            }
                            else if (!string.IsNullOrEmpty(controlInfo.ClassType))
                            {
                                var type  = controlInfo.ClassType;
                                var oType = Type.GetType(type);
                                if (!typeof(Control).IsAssignableFrom(oType))
                                {
                                    throw new System.Exception("The type {0} is not derived from System.Web.UI.Control");
                                }
                                var control = (Control)Activator.CreateInstance(oType);
                                this.Controls.Add(control);
                            }
                        }
                    }
                    pageInfo._controlsAdded = true;
                }
                if (!pageInfo._stylesAdded)
                {
                    foreach (var style in manager.Styles)
                    {
                        var linkTag = new System.Web.UI.HtmlControls.HtmlGenericControl("link");
                        linkTag.Attributes.Add("href", Page.ResolveClientUrl(style.Path));
                        linkTag.Attributes.Add("rel", "stylesheet");
                        linkTag.Attributes.Add("type", "text/css");
                        this.Page.Header.Controls.Add(linkTag);
                    }
                    pageInfo._stylesAdded = true;
                }
            }
        }
        //[Bindable(true)]
        //[Category("Appearance")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public string Text
        //{
        //    get
        //    {
        //        String s = (String)ViewState["Text"];
        //        return ((s == null) ? String.Empty : s);
        //    }

        //    set
        //    {
        //        ViewState["Text"] = value;
        //    }
        //}

        protected override void RenderContents(HtmlTextWriter output)
        {
            var manager  = PageModuleManager.Instance;
            var pageInfo = PageModuleManager.Get(this);

            if (manager != null && manager.HasScripts)
            {
                if (!pageInfo._scriptsRendered)
                {
                    foreach (var script in manager.Scripts)
                    {
                        output.AddAttribute(HtmlTextWriterAttribute.Src, Page.ResolveClientUrl(script.Path));
                        output.RenderBeginTag(HtmlTextWriterTag.Script);
                        output.RenderEndTag();
                    }
                    pageInfo._scriptsRendered = true;
                }
            }
        }