我有三个类和一个用户控件将使用这三个类。
这里是类及其解释:为什么我不能在WebForm中声明UserControl的子元素(属性)?
//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;
}
所以这里就是我要找的结构的一个例子:
<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>
的问题是,ASP.net识别SelectMethod为一个内部标签,它甚至将Method标签识别为内部标签,但它不能识别实际为ManagementMethod的Method标签的类型。当我将任何属性的类型更改为简单类型时,例如将List更改为ManagementMethod,ASP.net就会识别它并且一切正常。您也可以使用任何列表<>对象。
呀!我第一次提到这件事。感谢代码,但仍然有相同的问题!仍然说名称不是元素Method的正确属性。 – jim 2012-01-06 12:23:13
@RichardFriend这是一个很好的答案,并且(不幸地)被严重低估了,非常感谢我的+1。 – atlaste 2013-04-17 10:08:44