Link to home
Start Free TrialLog in
Avatar of ptmcomp
ptmcompFlag for Switzerland

asked on

Persistency for Properties provided by PropertyExtender (IExtenderProvider) for ASP.NET

I made a property extender for ASP.NET. It works so far but the properties are not persistent. I would like to make the properties persistent inside the particular WebControl (as Attribute or Element). Is this possible and how? If not how can I make the properties persistent and managable?


using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace PropertyExtenderTestApp
{
      /// <summary>
      /// Summary description for MyPropertyExtender.
      /// </summary>
      [ProvideProperty("TestProperty", typeof(WebControl))]
      public class MyPropertyExtender: Component, System.ComponentModel.IExtenderProvider
      {
            #region ------------ fields ------------

            private Hashtable myPropertyValues;

            #endregion

            #region ------------ constructors ------------

            public MyPropertyExtender()
            {
                  myPropertyValues = new Hashtable();
            }

            public MyPropertyExtender(IContainer parent) : this()
            {
                  parent.Add(this);
            }

            #endregion

            #region ------------ public methods ------------

            public bool CanExtend(object obj)
            {
                  return (obj is WebControl);
            }

            [DefaultValue(""),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            public string GetTestProperty(Control control)
            {
                  string text = (string)myPropertyValues[control];
                  if (text == null)
                  {
                        text = string.Empty;
                  }
                  return text;
            }

            public void SetTestProperty(Control control, string value)
            {
                  if (value == null)
                  {
                        value = string.Empty;
                  }
                  myPropertyValues[control] = value;
            }

            private bool ShouldSerializeTestProperty(Control control)
            {
                  return (myPropertyValues[control] != null);
            }

            private void ResetTestProperty(Control control)
            {
                  SetTestProperty(control, "");
            }

            #endregion
      }
}
ASKER CERTIFIED SOLUTION
Avatar of rajaloysious
rajaloysious

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ptmcomp

ASKER

Sorry, I forgot this Q.  Can you give me a short example. Then you will get grade A.
Avatar of ptmcomp

ASKER

I gave you the points without verifying it. I solved it differently.