ASPX.CS里的代码:
UserControl uc = (UserControl)LoadControl(actionOne[1].ToString());
uc.GetType().GetProperty("cid").SetValue(uc, cid.ToString(), null);//主要就在这里,这里是添加属性,并赋值。
uc.GetType().GetProperty("aid").SetValue(uc, id.ToString(), null);
pageAscx.Controls.Add(uc);
以下是ASCX下面的代码
public string _cid = "0";
public string _aid = "0";
public string cid
{
get
{
return _cid;
}
set
{
_cid = value;
}
}
public string aid
{
get
{
return _aid;
}
set
{
_aid = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}