2010-06-05 43 views
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(); 
    } 
} 

回答

1

而不是使用一個私人領域,我創建了一個公共財產和通過,而不是一個構造函數的設定值,並能正常工作。

相關問題