I am trying to make a web page that loads image buttons and other controls, where these buttons leads to another image buttons and other controls that have event handlers that do the same for illustration:
1- When the page loads i need to view all parent folders as image buttons using database:
protected void popAllParent()
{
Reporting repo = new Reporting();
foreach (Reporting item in repo.getAllFolders())
{
Label labelFold = new Label();
CheckBox chb = new CheckBox();
RadioButton rad = new RadioButton();
ImageButton imgBtn = new ImageButton();
labelFold.Text = " " + item.FolderName;
labelFold.Attributes.Add("pfolderID", item.FoldID);
chb.Attributes.Add("pfolderID", item.FoldID);
rad.Attributes.Add("pfolderID", item.FoldID);
rad.GroupName = "foldDelete";
imgBtn.ImageUrl = "~/Style/images/folder.png";
imgBtn.ID = "imgPfold" + item.FoldID;
imgBtn.Attributes.Add("pfolderID", item.FoldID);
imgBtn.Width = 50;
imgBtn.Height = 50;
imgBtn.Click += new ImageClickEventHandler(ImageButton1_Click);
Panel1.Controls.Add(labelFold);
Panel1.Controls.Add(new LiteralControl(" "));
Panel1.Controls.Add(chb);
Panel1.Controls.Add(new LiteralControl(" "));
Panel1.Controls.Add(rad);
Panel1.Controls.Add(new LiteralControl("<br />"));
Panel1.Controls.Add(imgBtn);
Panel1.Controls.Add(new LiteralControl("<br />"));
}
}
2- for each img button there is an event handler leads to subfolders method:
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
ImageButton ibtn = (ImageButton)sender;
ViewState["Sample"] = ibtn.Attributes["pfolderID"].ToString();
popAllSub(ibtn.Attributes["pfolderID"].ToString());
}
protected void popAllSub(string pfID)
{
Reporting repo = new Reporting();
Panel1.Controls.Clear();
foreach (Reporting item in repo.getAllSubFolders(pfID))
{
Label labelFold = new Label();
CheckBox chb = new CheckBox();
RadioButton rad = new RadioButton();
ImageButton imgBtn = new ImageButton();
labelFold.Text = " " + item.FolderName;
labelFold.Attributes.Add("pfolderID", item.FoldID);
chb.Attributes.Add("pfolderID", item.FoldID);
rad.Attributes.Add("pfolderID", item.FoldID);
rad.GroupName = "foldDelete";
imgBtn.ImageUrl = "~/Style/images/folder.png";
imgBtn.Attributes.Add("pfolderID", item.FoldID);
imgBtn.ID = "imgSfold" + item.FoldID;
imgBtn.Width = 35;
imgBtn.Height = 35;
imgBtn.Click += new ImageClickEventHandler(ImageButton1_Click);
Panel2.Controls.Add(labelFold);
Panel2.Controls.Add(new LiteralControl(" "));
Panel2.Controls.Add(chb);
Panel2.Controls.Add(new LiteralControl(" "));
Panel2.Controls.Add(rad);
Panel2.Controls.Add(new LiteralControl("<br />"));
Panel2.Controls.Add(imgBtn);
Panel2.Controls.Add(new LiteralControl("<br />"));
}
}
3- Folders in db is like this:
fName fID fType parentID
---------------------------------------
Quality 3 Child 1
Summary 1 Parent
Finance 2 Child 1
Quality 4 Parent
process 5 Child 4
processes 6 Child 4
Purchasing 7 Child 1
testFold 8 Child 7
As you see there are subfolder and inside it another subfolders. when the parent folders clicked, the event view the subfolders and the parent folders disappear, and when i try to click on the sub folders, every thing is disappeared and not reading the event handler. Please help me.