Solved

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

Posted on 2003-11-28
3
528 Views
Last Modified: 2012-05-04
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
Comment
Question by:ptmcomp
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
rajaloysious earned 500 total points
Comment Utility
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
 
LVL 10

Author Comment

by:ptmcomp
Comment Utility
Sorry, I forgot this Q.  Can you give me a short example. Then you will get grade A.
0
 
LVL 10

Author Comment

by:ptmcomp
Comment Utility
I gave you the points without verifying it. I solved it differently.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now