private static void PersistObject(HtmlTextWriter writer, object control, IDesignerHost host, bool runAtServer)
{
//look up tag prefix from host
IWebFormReferenceManager refMan = host.GetService (typeof (IWebFormReferenceManager)) as IWebFormReferenceManager;
if (refMan == null)
throw new Exception("Could not obtain IWebFormReferenceManager service");
string prefix = refMan.GetTagPrefix (control.GetType ());
//write tag to HtmlTextWriter
writer.WriteBeginTag (prefix + ":" + control.GetType().Name);
//go through all the properties and add attributes if necessary
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties (control);
foreach (PropertyDescriptor prop in properties)
ProcessAttribute (prop, control, writer, string.Empty);
if (runAtServer)
writer.WriteAttribute ("runat", "server");
//do the same for events
IComponent comp = control as IComponent;
if (comp != null && comp.Site != null) {
IEventBindingService evtBind = (IEventBindingService) comp.Site.GetService (typeof (IEventBindingService));
if (evtBind != null)
foreach (EventDescriptor e in TypeDescriptor.GetEvents (comp))
ProcessEvent (e, comp, writer, evtBind);
}
//ControlDesigner designer = (ControlDesigner) host.GetDesigner(control);
//TODO: we don't yet support designer.GetPersistInnerHtml() 'cause we don't have the designers...
if (HasInnerProperties(control)) {
writer.Write (HtmlTextWriter.TagRightChar);
writer.Indent++;
PersistInnerProperties (writer, control, host);
writer.Indent--;
writer.WriteEndTag (prefix + ":" + control.GetType ().Name);
}
else
writer.Write (HtmlTextWriter.SelfClosingTagEnd);
writer.WriteLine ();
writer.Flush ();
}