Solved

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

Posted on 2003-11-28
3
537 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
ID: 10857942
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
ID: 11183573
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
ID: 11577947
I gave you the points without verifying it. I solved it differently.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

821 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