示例#1
0
        protected override void OnInit(EventArgs e)
        {
            // Init
            PlaceHolder       plc;
            ControlCollection col = this.Controls;

            // Set template directory
            if (this._templateDir == null && ConfigurationManager.AppSettings["TemplateDir"] != null)
            {
                this._templateDir = ConfigurationManager.AppSettings["TemplateDir"];
            }

            // Get the template control
            if (this._templateFilename == null)
            {
                this._templateFilename = ConfigurationManager.AppSettings["DefaultTemplate"];
            }

            this._pageControl = (BasePageControl)this.LoadControl(this.ResolveUrl(this._templateDir + this._templateFilename));

            // Add the pagecontrol on top of the control collection of the page
            _pageControl.ID = "p";
            col.AddAt(0, _pageControl);

            // Get the Content placeholder
            plc = _pageControl.Content;
            if (plc != null)
            {
                // Iterate through the controls in the page to find the form control.
                foreach (Control control in col)
                {
                    if (control is HtmlForm)
                    {
                        // We've found the form control. Now move all child controls into the placeholder.
                        HtmlForm formControl = (HtmlForm)control;
                        while (formControl.Controls.Count > 0)
                        {
                            plc.Controls.Add(formControl.Controls[0]);
                        }
                    }
                }
                // throw away all controls in the page, except the page control
                while (col.Count > 1)
                {
                    col.Remove(col[1]);
                }
            }
            base.OnInit(e);
        }
        protected override void OnInit(EventArgs e)
        {
            // Init
            PlaceHolder plc;
            ControlCollection col = this.Controls;

            // Set template directory
            if (this._templateDir == null && ConfigurationManager.AppSettings["TemplateDir"] != null)
            {
                this._templateDir = ConfigurationManager.AppSettings["TemplateDir"];
            }

            // Get the template control
            if (this._templateFilename == null)
            {
                this._templateFilename = ConfigurationManager.AppSettings["DefaultTemplate"];
            }

            this._pageControl = (BasePageControl)this.LoadControl(this.ResolveUrl(this._templateDir + this._templateFilename));

            // Add the pagecontrol on top of the control collection of the page
            _pageControl.ID = "p";
            col.AddAt(0, _pageControl);

            // Get the Content placeholder
            plc = _pageControl.Content;
            if (plc != null)
            {
                // Iterate through the controls in the page to find the form control.
                foreach (Control control in col)
                {
                    if (control is HtmlForm)
                    {
                        // We've found the form control. Now move all child controls into the placeholder.
                        HtmlForm formControl = (HtmlForm)control;
                        while (formControl.Controls.Count > 0)
                            plc.Controls.Add(formControl.Controls[0]);
                    }
                }
                // throw away all controls in the page, except the page control
                while (col.Count > 1)
                    col.Remove(col[1]);
            }
            base.OnInit(e);
        }