public override string GetEditableDesignerRegionContent(EditableDesignerRegion region) { IDesignerHost service = (IDesignerHost)CurrentControl.Site.GetService(typeof(IDesignerHost)); if (service != null) { if (region.Name == "Items") { StringBuilder sb = new StringBuilder(); foreach (ControlBase c in CurrentControl.Items) { sb.Append(ControlPersister.PersistControl(c, service)); } //sb.Append(ControlPersister.PersistControl(CurrentControl.Items[1], service)); //sb.Append("<ext:CheckBox runat=\"server\" Text=\"Click to postback\" Checked=\"True\" AutoPostBack=\"True\" Label=\"CheckBox\" ID=\"CheckBox1\" __designer:mapid=\"4\" OnCheckedChanged=\"CheckBox1_CheckedChanged\"></ext:CheckBox>"); //sb.Append("<ext:CheckBox runat=\"server\" Text=\"Click to postback\" Checked=\"True\" AutoPostBack=\"True\" Label=\"CheckBox\" ID=\"CheckBox1\" OnCheckedChanged=\"CheckBox1_CheckedChanged\"></ext:CheckBox>"); return(sb.ToString()); } else if (region.Name == "Toolbars") { StringBuilder sb = new StringBuilder(); foreach (Toolbar c in CurrentControl.Toolbars) { sb.Append(ControlPersister.PersistControl(c, service)); } return(sb.ToString()); } } return(String.Empty); }
public override string GetEditableDesignerRegionContent(EditableDesignerRegion region) { IDesignerHost service = (IDesignerHost)CurrentControl.Site.GetService(typeof(IDesignerHost)); if (service != null) { if (region.Name == "Items") { StringBuilder sb = new StringBuilder(); foreach (ControlBase c in CurrentControl.Items) { sb.Append(ControlPersister.PersistControl(c, service)); } return(sb.ToString()); } else if (region.Name == "Toolbars") { StringBuilder sb = new StringBuilder(); foreach (Toolbar c in CurrentControl.Toolbars) { sb.Append(ControlPersister.PersistControl(c, service)); } return(sb.ToString()); } } return(String.Empty); }
public override string GetEditableDesignerRegionContent(EditableDesignerRegion region) { IDesignerHost service = (IDesignerHost)base.Component.Site.GetService(typeof(IDesignerHost)); if (service != null) { int rowIndex = Convert.ToInt32(region.Properties["RowIndex"]); StringBuilder sb = new StringBuilder(); foreach (ControlBase c in CurrentControl.Rows[rowIndex].Items) { sb.Append(ControlPersister.PersistControl(c, service)); } return(sb.ToString()); #region old code // table不会自动更新,还不如先不用 ////int rowIndex = Convert.ToInt32(region.Name.Substring(EDITOR_REGION_PREFIX.Length)); //int rowIndex = Convert.ToInt32(region.Properties["RowIndex"]); //ControlBaseCollection controls = CurrentControl.Rows[rowIndex].Items; //StringBuilder sb = new StringBuilder(); //sb.Append("<table cellpadding='0' cellspacing='0' border='0' style='width:100%;'><tbody><tr>"); //string columnWidthStr = (1.0 / controls.Count * 100).ToString("F0") + "%"; //if (controls.Count == 0) //{ // sb.Append("<td style='width:100%;'></td>"); //} //else //{ // foreach (ControlBase c in controls) // { // sb.AppendFormat("<td style='width:{0};'>", columnWidthStr); // sb.Append(ControlPersister.PersistControl(c, service)); // sb.Append("</td>"); // } //} //sb.Append("</tr></tbody></table>"); ////sb.Append(ControlPersister.PersistControl(CurrentControl.Rows[rowIndex].Fields[columnIndex], service)); //return sb.ToString(); #endregion } return(String.Empty); }
public override string GetEditableDesignerRegionContent(EditableDesignerRegion region) { IDesignerHost service = (IDesignerHost)base.Component.Site.GetService(typeof(IDesignerHost)); if (service != null) { StringBuilder sb = new StringBuilder(); foreach (ControlBase c in CurrentControl.Items) { sb.Append(ControlPersister.PersistControl(c, service)); } return(sb.ToString()); } return(String.Empty); }
private string GetTemplateContent(ITemplate template, string id) { DesignerPanel contentPanel = new DesignerPanel(); contentPanel.ID = id; template.InstantiateIn(contentPanel); IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); Debug.Assert(host != null, "Failed to get IDesignerHost?!?"); StringBuilder persistedControl = new StringBuilder(1024); foreach (System.Web.UI.Control c in contentPanel.Controls) { persistedControl.Append(ControlPersister.PersistControl(c, host)); } return(persistedControl.ToString()); }
public override string GetEditableDesignerRegionContent(EditableDesignerRegion region) { IDesignerHost service = (IDesignerHost)base.Component.Site.GetService(typeof(IDesignerHost)); if (service != null) { if (region.Name == "Content") { Tab tab = CurrentControl.Tabs[CurrentControl.ActiveTabIndex]; StringBuilder sb = new StringBuilder(); foreach (Control c in tab.Items) { sb.Append(ControlPersister.PersistControl(c, service)); } return(sb.ToString()); // return ControlPersister.PersistControl(CurrentControl.Tabs[CurrentControl.ActiveTabIndex], service); } } return(String.Empty); }
private void ConvertPersistedControlsToLiteralControls(Control defaultTemplateContents) { foreach (string str in this.PersistedControlIDs) { Control control = defaultTemplateContents.FindControl(str); if (control != null) { if (Array.IndexOf <string>(this.PersistedIfNotVisibleControlIDs, str) >= 0) { control.Visible = true; control.Parent.Visible = true; control.Parent.Parent.Visible = true; } if (control.Visible) { LiteralControl child = new LiteralControl(ControlPersister.PersistControl(control, this._designerHost)); ControlCollection controls = control.Parent.Controls; int index = controls.IndexOf(control); controls.Remove(control); controls.AddAt(index, child); } } } }
// Displays a list of controls in the project, if any, // and displays the HTML markup for the selected control. private void saveControl() { // Get the collection of components in the current // design mode document. ComponentCollection documentComponents = this.Component.Site.Container.Components; // Filter the components to those that derive from the // System.Web.UI.Control class. // Create an IComponent array of the maximum possible length needed. IComponent[] filterArray = new IComponent[documentComponents.Count]; // Count the total qualifying components. int total = 0; for (int i = 0; i < documentComponents.Count; i++) { // If the component derives from System.Web.UI.Control, // copy a reference to the control to the filterArray // array and increment the control count. if (typeof(System.Web.UI.Control).IsAssignableFrom( documentComponents[i].GetType())) { if (((System.Web.UI.Control)documentComponents[i]).UniqueID != null) { filterArray[total] = documentComponents[i]; total++; } } } if (total == 0) { throw new Exception( "Document contains no System.Web.UI.Control components."); } // Move the components that derive from System.Web.UI.Control to a // new array of the correct size. System.Web.UI.Control[] controlArray = new System.Web.UI.Control[total]; for (int i = 0; i < total; i++) { controlArray[i] = (System.Web.UI.Control)filterArray[i]; } // Create a ControlSelectionForm to select a control. ControlSelectionForm selectionForm = new ControlSelectionForm(controlArray); // Display the form. if (selectionForm.ShowDialog() != DialogResult.OK) { return; } // Validate the selection. if (selectionForm.controlList.SelectedIndex == -1) { throw new Exception("You must select a control to persist."); } //<Snippet3> // Parse the selected control into a persistence string. string persistedData = ControlPersister.PersistControl( controlArray[selectionForm.controlList.SelectedIndex]); //</Snippet3> // Display the persistence string in a text box. StringDisplayForm displayForm = new StringDisplayForm(persistedData); displayForm.ShowDialog(); }
///<summary>Converts a designer document fragment to ASP.NET code</summary> public string Serialize(string designerDocumentFragment) { if (host == null) { throw new Exception("The document cannot be persisted without a host"); } string serializedDoc = string.Empty; StringWriter writer = new StringWriter(); //keep method argument meaningfully named, but keep code readable! string frag = designerDocumentFragment; int length = frag.Length; int pos = 0; SMode mode = SMode.Free; while (pos < length) { char c = frag [pos]; switch (mode) { //it's freely copying to output, but watching for a directive or control placeholder case SMode.Free: if (c == '<') { if ((pos + 10 < length) && frag.Substring(pos + 1, 10) == "aspcontrol") { mode = SMode.ControlId; pos += 10; break; } else if ((pos + 20 < length) && frag.Substring(pos + 1, 20) == "directiveplaceholder") { mode = SMode.DirectiveId; pos += 20; break; } } writer.Write(c); break; //it's found a directive placeholder and is scanning for the ID case SMode.DirectiveId: if (c == 'i' && (pos + 4 < length) && frag.Substring(pos, 4) == "id=\"") { int idEnd = frag.IndexOf('"', pos + 4 + 1); if (idEnd == -1) { throw new Exception("Identifier was unterminated"); } int id = Int32.Parse(frag.Substring(pos + 4, (idEnd - pos - 4))); //TODO: more intelligent removal/copying of directives in case of fragments //works fine with whole document. string directive = RemoveDirective(id); writer.Write(directive); mode = SMode.DirectiveEnd; pos = idEnd; } break; //it's found a control placeholder and is scanning for the ID case SMode.ControlId: if (c == 'i' && (pos + 4 < length) && frag.Substring(pos, 4) == "id=\"") { int idEnd = frag.IndexOf("\"", pos + 4); if (idEnd == -1) { throw new Exception("Identifier was unterminated"); } string id = frag.Substring(pos + 4, (idEnd - pos - 4)); DesignContainer dc = (DesignContainer)host.Container; Control control = dc.GetComponent(id) as Control; if (control == null) { throw new Exception("Could not retrieve control " + id); } ControlPersister.PersistControl(writer, control); mode = SMode.ControlEnd; pos = idEnd; } break; //it's found the control's ID and is looking for the end case SMode.ControlEnd: if (c == '<' && (pos + 13 < length) && frag.Substring(pos, 13) == "</aspcontrol>") { pos += 12; mode = SMode.Free; } break; //it's found the placeholder's ID and is looking for the end case SMode.DirectiveEnd: if (c == '/' && (pos + 2 < length) && frag.Substring(pos, 2) == "/>") { pos += 1; mode = SMode.Free; } break; } pos++; } serializedDoc = writer.ToString(); writer.Close(); return(serializedDoc); }