We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Persisting programmatically changed (set) property.

Thread ID:





12527 Apr 1,2004 02:47 PM UTC Jun 13,2004 07:27 AM UTC Windows Forms 1
Tags: FAQ
Oleg Slyusarchuk
Asked On April 1, 2004 02:47 PM UTC

Your Windows Forms FAQ inspired me and opened eyes om some problems, helped to solve many Design-time issues. At the present, I’m desperately trying to solve the problem for (you'd not believe) more than 3 weeks. I posted the question at many places (Microsoft’s newsgroups – many times, gotdonet.com, codeproject.com, … ) All my posting were left unanswered. There can be a little detail I’m missing. Below are my class ClickTestControl(significantly simplified ) and its designer - ClickTestDesigner . ClickTestControl has a property called "CurrentState". I would like to set the property programmatically in designer mode. I'm able to do that, I see the changed value in a property Grid, I see that OnComponentChanged is called. However, this value does not persist in a web form. This property does persist if I change the property in the property Grid manually. Any suggestions are greatly appreciated. Oleg P.S. for your convenience I also attached my sample solution. ------------ using System; using System.Drawing ; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; using ClickTestControls.Design; [assembly: TagPrefix ("TestControls", "CLICK")] namespace TestControls { [ ToolboxData("<{0}:ClickTestControl runat=server>"), Designer(typeof(ClickTestDesigner))] public class ClickTestControl : Control, INamingContainer { private string _currentState; [ PersistenceMode(PersistenceMode.Attribute), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible ) ] public string CurrentState { get { return _currentState; } set { _currentState=value; } } protected override void CreateChildControls() { Controls.Add (new LiteralControl ("Some dummy Literal")); } } } // Designer using System; using System.Drawing; using System.Drawing.Design; using System.Web.UI; using System.Web.UI.Design; using System.Web.UI.WebControls; using System.ComponentModel; using System.ComponentModel.Design; using TestControls; namespace ClickTestControls.Design { public class ClickTestDesigner : System.Web.UI.Design.ControlDesigner { private ClickTestControl thisControl; public override void Initialize(System.ComponentModel.IComponent component) { base.Initialize (component); thisControl = (ClickTestControl)component; this.IsDirty = true; // try force saving changes made programmatically if (thisControl.CurrentState == null || thisControl.CurrentState ==string.Empty ) { string newValue = "Some Value from somewhere..." ; PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(thisControl); PropertyDescriptor myProperty = properties.Find("CurrentState",true); // 2 lines trying to achieve the same goal if (myProperty != null ) myProperty.SetValue(this.Component,newValue); thisControl.CurrentState = newValue; RaiseComponentChanged ((MemberDescriptor)myProperty, null,newValue); TypeDescriptor.Refresh(this.Component); } } public override String GetDesignTimeHtml() { String strHtml = ""; strHtml += " ;