I have three classes and a user control that will use these three classes.
Here are the classes and their explanations:
//provides access to multiple ManagementMethods
[Serializable(), ParseChildren(true)]
public class ManagementDelegate
{
[Browsable(true), EditorBrowsable(EditorBrowsableState.Always),
PersistenceMode(PersistenceMode.InnerProperty)]
public List<ManagementMethod> Method
{
get; set;
}
}
//provides access to multiple ManagementParameters and the method name
[Serializable(), PersistChildren(false)]
public class ManagementMethod
{
[Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
public string Name
{
get; set;
}
[Browsable(true), EditorBrowsable(EditorBrowsableState.Always),
PersistenceMode(PersistenceMode.InnerProperty)]
public List<ManagementParameter> Parameter
{
get; set;
}
}
//describes a parameter of method.
[Serializable(), PersistChildren(false)]
public class ManagementParameter
{
[Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
public string ParameterName
{
get; set;
}
}
//===============================
//here is the part of user control code behind that uses the ManagementDelegate class.
[Browsable(true), EditorBrowsable(EditorBrowsableState.Always),
PersistenceMode(PersistenceMode.InnerProperty)]
public ManagementDelegate SelectMethods
{
get; set;
}
So here is an example of the structure that I’m looking for:
<UC:MyUc ID="test" runat="server">
<SelectMethods>
<!-- here when i open a tag asp.net lists the Method, but when i try to set the Name attribute it warns and won't run. -->
<Method Name="meth">
<Parameter ParameterName="id" />
<Parameter ParameterName="word" />
</Method
<Method Name="meth2">
</Method
</SelectMethods>
</UC:MyUc>
The problem is that ASP.net recognizes the SelectMethod as an inner tag, it even recognizes the Method tag as an inner tag but it doesn’t recognize the type of Method tag which actually is ManagementMethod. When I change the type of any of the properties to a simple type, for example change the List to just ManagementMethod, ASP.net recognizes it and everything works fine. Thee same goes with any List<> object.
Here is a snippet from our production code, you can see that the
ControlDependencyclass even allows children ofControlDependencyAnd is declared in the custom control as
Also note that i do create an instance of these lists in each constructor.
*EDIT***
You have called your list
Methodand your elementMethod, you are expecting child elements ofManagementDelegateto be automatically added to the list calledMethod, this is not how it works, when you want to add to the list you need to specify the list element and add inside of it , you have done the same for parameters.This is what your current structure would be expecting.
You should rename to
MethodsandParametersand use accordingly or re-structure your layout.Something like
Then
I believe there may also be away to specify that innner content belongs to a specific property by default, see PersistenceMode.InnerDefaultProperty – but i have never tried this.