我有一个名为“DashboardUserControl.ascx”的用户控件
它有一个功能:
public void setPagination(Boolean pagination)
{
this.DashboardGridView.AllowPaging = pagination;
}
我有另外两个页面,通过拖放插入了该用户控件:
MyDashboard.aspx:我想从此页面将用户控件的分页设置为“true”。
SharedDashboard.aspx:我想将用户控件的分页设置为“false”。
怎么做?
答案 0 :(得分:1)
如果您将usercontrol添加到这两个页面,那么您有两个usercontrol实例。这意味着页面上的用户控件未连接。
因此,要调用该方法,您可以在页面的Page_Load中简单地执行以下操作。以下代码示例适用于MyDashboard.aspx.cs。在SharedDashboard.aspx.cs中将 true 更改为 false 。
protected void Page_Load(object sender, EventArgs e) {
this.DashboardUserControl.setPagination(true);
}
答案 1 :(得分:1)
要么你:
或(我更喜欢)
将方法重写为属性:
public bool Pagination
{
set { this.DashboardGridView.AllowPaging = value; }
get { return this.DashboardGridView.AllowPaging; }
}
如果您添加了该属性,则可以在 中从代码后面或从MyDashboard.aspx和SharedDashboard.aspx的标记为其分配值。
例如。 <uc:MyControl id="myControl1" Pagination="true" runat="server" />
希望这有帮助