0
在下面的代碼中,爲什麼在Page_Load事件期間groupId值重置爲0?爲什麼我的ASP.NET用戶控件的字段值重置爲0?
也許也許用groupId創建的AccountGrid不是加載到頁面的那個?
public partial class AccountGrid : System.Web.UI.UserControl
{
int groupId = 0;
public AccountGrid()
{
}
// an aspx page creates AccountGrid with "new AccountGrid(1)"
public AccountGrid(int groupId)
{
this.groupId = groupId;
}
protected void Page_Load(object sender, EventArgs e)
{
DataAccessFacade facade = new DataAccessFacade();
// groupId resets to 0 here...
grdAccount.DataSource = facade.GetAccountsByAccountGroupId(this.groupId);
grdAccount.DataBind();
}
}
在我的網頁,我有
public partial class Default : System.Web.UI.Page
{
public Default()
{
}
public void Page_Load(object sender, EventArgs e)
{
ctlAccountGrid = new Views.Controls.Account.AccountGrid(1);
// should I do databind?
ctlAccountGrid.DataBind();
}
}