public override void SetEditableDesignerRegionContent(EditableDesignerRegion region, string content) { if (content == null) { return; } IDesignerHost host = (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost)); if (host != null) { ITemplate template = ControlParser.ParseTemplate(host, content); if (template == null) { this.viewPort.Content = template; this.viewPort.ContentContainer.Controls.Clear(); this.ChangeService(); return; } Control control = ControlParser.ParseControl(host, content); if (control is Layout) { bool needRefresh = this.viewPort.LayoutControl == null; this.viewPort.Content = template; this.viewPort.ContentContainer.Controls.Clear(); this.viewPort.ContentContainer.Controls.Add(control); if (needRefresh) { this.ChangeService(); } } else { /* * NOTE: We need to call ChangeService for clear content template if user drop not layout * But if control have ActionList then after drop this ActionList will be shown * If we call ChangeService at this moment than VS will crash because trying show * ActionList not exists control * * Need find solution for fixed it */ // this.ChangeService(); } } }
// Displays a textbox form to receive an HTML // string that represents a control, and creates // a toolbox item for the control, if not already // present in the selected toolbox category. private void loadPersistedControl() { // Display a StringInputForm to obtain a persisted control string. StringInputForm inputForm = new StringInputForm(); if (inputForm.ShowDialog() != DialogResult.OK) { return; } if (inputForm.TBox.Text.Length < 2) { return; } // Obtain an IDesignerHost for the design-mode document. IDesignerHost host = (IDesignerHost) this.Component.Site.GetService(typeof(IDesignerHost)); //<Snippet2> // Create a Web control from the HTML markup. System.Web.UI.Control ctrl = ControlParser.ParseControl(host, inputForm.TBox.Text.Trim()); //</Snippet2> // Create a Web control toolbox item for the type of the control System.Web.UI.Design.WebControlToolboxItem item = new System.Web.UI.Design.WebControlToolboxItem(ctrl.GetType()); // Add the Web control toolbox item to the toolbox IToolboxService toolService = (IToolboxService) this.Component.Site.GetService(typeof(IToolboxService)); if (toolService != null) { toolService.AddToolboxItem(item); } else { throw new Exception("IToolboxService was not found."); } }