我有一個動態加載用戶控件的網頁。每個用戶控件都可以遞歸地在它自己內部加載相同的控件。每個控件都有一個刪除按鈕。我遇到的問題是,當用戶點擊刪除按鈕,我需要刪除的刪除按鈕包含在控制刪除動態用戶控件
頁面控件集合可以如下所示:
Page
Group 1
Category Control
Category Control
Category Control
Category Control
Category Control
Category Control
如何刪除新創建的類別控制。我已經試過這個.Dispose,但它不起作用。
在動態加載上加我的用戶控件的主要頁面有:
protected void cmdsubmitsofficecat_Click(object sender, EventArgs e)
{
int retvalue = 0;
SQLConnectivity db = new SQLConnectivity();
SqlParameter[] param = new SqlParameter[8];
List<group.category> flist = new List<group.category>();
param[0] = db.MakeInputParameter("@group_id", 1);
param[1] = db.MakeInputParameter("@parent_id", DBNull.Value);
param[2] = db.MakeInputParameter("@category_name", this.txtofficecat.Text.Trim());
param[3] = db.MakeInputParameter("@description", this.txtofficecat.Text.Trim());
param[4] = db.MakeInputParameter("@organization_id", 1);
param[5] = db.MakeInputParameter("@created_by", 1);
param[6] = db.MakeInputParameter("@is_active", 1);
param[7] = db.MakeOutputIntegerParameter("@category_id");
db.RunNonQueryProcedure("PerformanceCategorySave", param, ref retvalue);
if (retvalue != 0)
{
group.category item = new group.category();
item.catid = retvalue;
item.catname = this.txtofficecat.Text.Trim();
item.desc = this.txtofficecat.Text.Trim();
item.isactive = true;
item.parid = 0;
catctl ctl = (catctl)Page.LoadControl("~/catctl.ascx");
ctl.groupid = 1;
ctl.organizationid = 1;
ctl.categoryid = item.catid;
ctl.categoryname = item.catname;
ctl.parentid = item.parid;
ctl.ctltype = 1;
ctl.clist = item.categories;
ctl.plist = item.points;
this.officephld.Controls.Add(ctl);
this.switch_officefields(false, 1);
}
}
在web用戶控件我有一個Page_Load方法爲:
protected void Page_Load(object sender, EventArgs e)
{
Label ctname = (Label)this.FindControl("ctl0_catname");
this.catname.Text = categoryname;
this.cmdaddcat.Attributes.Add("catid", categoryid.ToString());
this.cmddeletecat.ID = "cmddeletecat" + categoryid.ToString();
this.cmddeletecat.Click += new ImageClickEventHandler(this.cmddeletecat_Click);
if (clist != null && clist.Count > 0)
{
int i = 0;
this.cmddeletecat.Visible = false;
foreach (group.category item in clist)
{
catctl ctl = (catctl)Page.LoadControl("~/catctl.ascx");
ctl.categoryid = item.catid;
ctl.categoryname = item.catname;
ctl.organizationid = organizationid;
ctl.groupid = groupid;
ctl.parentid = item.parid;
ctl.clist = item.categories;
ctl.plist = item.points;
ctl.ctltype = ctltype;
this.newphld.Controls.Add(ctl);
}
}
if (plist != null && plist.Count > 0)
{
this.rptPts.Visible = true;
this.rptPts.DataSource = plist;
this.rptPts.DataBind();
this.cmddeletecat.Visible = false;
}
this.Switch_Usability();
}
和刪除方法:
protected void cmddeletecat_Click(object sender, ImageClickEventArgs e)
{
List<group.category> flist = new List<group.category>();
SQLConnectivity db = new SQLConnectivity();
SqlParameter[] param = new SqlParameter[1];
DataTable dt = new DataTable();
DataTable sdt = new DataTable();
group parent = new group();
param[0] = db.MakeInputParameter("@category_id", categoryid);
db.RunNonQueryProcedure("PerformanceCategoryDelete", param);
if (Page != null)
{
PlaceHolder ctl = (PlaceHolder)Page.FindControl("officephld");
if (ctl != null)
{ ctl.Controls.Remove(this); }
}
}
是不是這個ctl.Controls.Remove(this);加工?在你之間也試一試cmddeletecat_Click - > this.NamingContainer.Controls.Remove(this); – Waqas