我有三个行为非常相似的页面,所以我制作了一个具有 3 种行为的用户控件,我通过添加一个枚举和这个枚举类型的属性来做到这一点。
public enum ucType
{
CustomersWhoHaveAContract, CustomersWaitingForContract, CustomerOfPreReservedContracts
}
public ucType UserControlType;
protected void BtnLoadInfo_Click(object sender, ImageClickEventArgs e)
{
switch (UserControlType)
{
case ucType.CustomersWhoHaveAContract:
DoA();
break;
case ucType.CustomersWaitingForContract:
DoB();
break;
case ucType.CustomerOfPreReservedContracts:
DoC();
break;
default:
break;
}
在我的页面中,我为 UserControlType 赋值,
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ucCustomersWithContract1.UserControlType = UserControls.ucCustomersWithContract.ucType.CustomerOfPreReservedContracts;
}
}
但是当我单击按钮时, UserControlType 总是CustomersWhoHaveAContract
,这意味着它正在失去它的价值。哪里有问题?