I have a problem in finding control in a dynamically created updated panel. I have given the code below. Following is just a starting effort in a completely dynamic user control. I am experimenting before getting to the actual part. This is what I am trying to do:
* Create a tab container dynamically
* Create 5 tabs dynamically
* Add an update panel to each of the tabs
* Add a label to each of the update panels
* Add an OnLoad event to each of the tabs and change the contents of the label added
But I am not able to accomplish the last part, I am not sure how to access the label dynamically added to the update panel
I have given the code below. Please help me in this regard.
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Collections;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Xml.Linq;
- using AjaxControlToolkit;
- public partial class EvaluationsWidget : System.Web.UI.Page
- {
- protected string[] tabnames = {"All","Contact Centers","Networks","Technology Planning"};
- protected Label lbl;
- protected void Page_Load(object sender, EventArgs e)
- {
- ArrayList al = new ArrayList();
- for (int i = 0; i < 20; i++)
- al.Add(i.ToString());
- TabContainer tabContainer = new TabContainer();
- tabContainer.ID = "tbContainerMain";
- tabContainer.Width = 500;
- for (int i = 0; i < tabnames.Length; i++)
- {
- TabPanel tabPanel = new TabPanel();
- tabPanel.ID = "evaluationsPanel" + i.ToString();
- tabPanel.HeaderText = tabnames[i];
- tabPanel.Load += new EventHandler(tabPanel_Load);
- UpdatePanel updPanel = new UpdatePanel();
- updPanel.ID = "evaluationsUpdatePanel" + i.ToString();
- updPanel.UpdateMode = UpdatePanelUpdateMode.Conditional;
- lbl = new Label();
- lbl.ID = "lbl" + i.ToString();
- lbl.Text = "Label " + i.ToString();
- updPanel.ContentTemplateContainer.Controls.Add(lbl);
- tabPanel.Controls.Add(updPanel);
- tabContainer.Controls.Add(tabPanel);
- }
- form1.Controls.Add(tabContainer);
- }
- void tabPanel_Load(object sender, EventArgs e)
- {
- TabPanel tbPanel = (TabPanel)sender;
- //This doen't work, I need help here
- this.lbl.Text = "Clicked";
- }
- }
Thanks,
Karthik