• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 567
  • Last Modified:

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
      }
}
0
ptmcomp
Asked:
ptmcomp
  • 2
1 Solution
 
rajaloysiousCommented:
If derived classes are to do any custom persistence, they must override the SERIALIZE method, and first call base.Save() before doing their own persistence.
0
 
ptmcompAuthor Commented:
Sorry, I forgot this Q.  Can you give me a short example. Then you will get grade A.
0
 
ptmcompAuthor Commented:
I gave you the points without verifying it. I solved it differently.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now