I was wondering if anyone could help me with a simple problem:
I plan to create several asp.net server controls which use one xml file.
I have created a class (called Settings) which reads the xml file, exposes
various elements as properties or arrays, and performs other common
tasks. The class is in the same namespace and assembly.
I have referenced the class in my server control, but when I set the
XmlFile property at design time, it does not work. Here is the simple
code:
public class xxx : System.Web.UI.WebControls.WebControl
{
private Settings mysettings = new Settings();
?
/// <summary>
/// The xml configuration file
/// </summary>
[Bindable(true),
Category("Data"),
DefaultValue("AppSettings.xml"),
Description("The xml file containing configuration settings")]
public string XmlFile
{
get { return mysettings.XmlFile; }
set
{
//read in xml script and set properties
if ((value == string.Empty) || (value == null))
throw new ArgumentException("xxx requires an
XML settings file.");
//map the path
mysettings.XmlFile =
HttpContext.Current.Request.MapPath(value);
}
}
When I drop the control at design time, not only is the XmlFile setting
blank in the property window, but when I add an entry, I get this error:
Invalid property value
Object reference not set to an instance of an object.
Thanks for any ideas,
Andrew