ptmcomp
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.Desi gn;
namespace PropertyExtenderTestApp
{
/// <summary>
/// Summary description for MyPropertyExtender.
/// </summary>
[ProvideProperty("TestProp erty", typeof(WebControl))]
public class MyPropertyExtender: Component, System.ComponentModel.IExt enderProvi der
{
#region ------------ fields ------------
private Hashtable myPropertyValues;
#endregion
#region ------------ constructors ------------
public MyPropertyExtender()
{
myPropertyValues = new Hashtable();
}
public MyPropertyExtender(IContai ner parent) : this()
{
parent.Add(this);
}
#endregion
#region ------------ public methods ------------
public bool CanExtend(object obj)
{
return (obj is WebControl);
}
[DefaultValue(""),
DesignerSerializationVisib ility(Desi gnerSerial izationVis ibility.Co ntent)]
public string GetTestProperty(Control control)
{
string text = (string)myPropertyValues[c ontrol];
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 ShouldSerializeTestPropert y(Control control)
{
return (myPropertyValues[control] != null);
}
private void ResetTestProperty(Control control)
{
SetTestProperty(control, "");
}
#endregion
}
}
using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.ComponentModel.Desi
namespace PropertyExtenderTestApp
{
/// <summary>
/// Summary description for MyPropertyExtender.
/// </summary>
[ProvideProperty("TestProp
public class MyPropertyExtender: Component, System.ComponentModel.IExt
{
#region ------------ fields ------------
private Hashtable myPropertyValues;
#endregion
#region ------------ constructors ------------
public MyPropertyExtender()
{
myPropertyValues = new Hashtable();
}
public MyPropertyExtender(IContai
{
parent.Add(this);
}
#endregion
#region ------------ public methods ------------
public bool CanExtend(object obj)
{
return (obj is WebControl);
}
[DefaultValue(""),
DesignerSerializationVisib
public string GetTestProperty(Control control)
{
string text = (string)myPropertyValues[c
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 ShouldSerializeTestPropert
{
return (myPropertyValues[control]
}
private void ResetTestProperty(Control control)
{
SetTestProperty(control, "");
}
#endregion
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I gave you the points without verifying it. I solved it differently.
ASKER