/// <summary> /// <para> /// Gets the HTML to be persisted for the content present within the associated server control runtime. /// </para> /// </summary> /// <returns> /// <para> /// Persistable Inner HTML. /// </para> /// </returns> public override String GetPersistInnerHtml() { String persist = null; if (InTemplateMode) { SaveActiveTemplateEditingFrame(); } if (IsDirty) { persist = MobileControlPersister.PersistInnerProperties(Component, Host); } if (InTemplateMode) { IsDirty = true; } return(persist); }
/// <summary> /// <para> /// Gets the HTML to be persisted for the content present within the associated server control runtime. /// </para> /// </summary> /// <returns> /// <para> /// Persistable Inner HTML. /// </para> /// </returns> public override String GetPersistInnerHtml() { if (!IsDirty) { // Returning a null string will prevent the actual save. return(null); } StringWriter sw = new StringWriter(CultureInfo.InvariantCulture); // HACK ALERT: // We need to temporarily swap out the Text property to avoid being // persisted into control inner text. However, setting the Text property // will wipe out all control collections, therefore we need to cache // the Text value too. bool hasControls = _mobileControl.HasControls(); if ((_mobileControl is TextControl || _mobileControl is TextView) && hasControls) { String originalText = null; Control[] children = null; // Cache all child controls here. children = new Control[_mobileControl.Controls.Count]; _mobileControl.Controls.CopyTo(children, 0); // Replace the text with empty string. if (_mobileControl is TextControl) { originalText = ((TextControl)_mobileControl).Text; ((TextControl)_mobileControl).Text = String.Empty; } else { originalText = ((TextView)_mobileControl).Text; ((TextView)_mobileControl).Text = String.Empty; } try { // Persist inner properties without Text property. MobileControlPersister.PersistInnerProperties(sw, _mobileControl, Host); // Persist the child collections. foreach (Control c in children) { MobileControlPersister.PersistControl(sw, c, Host); } } finally { // Write the original text back to control. if (_mobileControl is TextControl) { ((TextControl)_mobileControl).Text = originalText; } else { ((TextView)_mobileControl).Text = originalText; } // Add the child controls back. foreach (Control c in children) { _mobileControl.Controls.Add(c); } } } else { MobileControlPersister.PersistInnerProperties(sw, _mobileControl, Host); } IsDirty = false; return(sw.ToString()); }