?
Solved

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

Posted on 2003-11-28
3
Medium Priority
?
557 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
rajaloysious earned 1500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

765 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