我找到了一种使用键值的解决方案,但问题是当我在像 MyUserControl1.Param.Key = "Area"; 这样的 .Cs 上使用它时 MyUserControl1.Param.Value = 面积
它不允许我这样做......下面是代码......
public partial class MyUserControl : System.Web.UI.UserControl
{
private Dictionary<string, string> labels = new Dictionary<string, string>();
public LabelParam Param
{
private get { return null; }
set
{
labels.Add(value.Key, value.Value);
}
}
public class LabelParam : WebControl
{
public string Key { get; set; }
public string Value { get; set; }
public LabelParam() { }
public LabelParam(string key, string value) { Key = key; Value = value; }
}
}
If I use it aspx page like below it work fine:
<%@ Register src="MyUserControl.ascx" tagname="MyUserControl" tagprefix="test" %>
<test:MyUserControl ID="MyUserControl1" runat="server">
<Param Key="d1" value="ddd1" />
<Param Key="d2" value="ddd2" />
<Param Key="d3" value="ddd3" />
</test:MyUserControl>