I have a .net TabControl - the tabs of which I am dynamically creating. Each tab has a form on it consisting of labels, textboxes, buttons and a datagrid. I am able to create the tabs just fine, however once a tab is created how do I access the dynamically created controls on it (i.e. the labels, textboxes, buttons and datagrid)?
A brief section of my code is shown in the code snippet below:
How would I get the text value of pnTextBox on a particular tab? How would I catch an event raised from a textchanged or button click even from contols on a particular tab?
Do I need to dynamically create event handler methods too?
Thanks for the help.
private void GeneratePartTabs(Int32 rmaID)
foreach (RMA2MainPart mainPart in RMA2MainPartList.List)
TabPage tabPage = new TabPage(mainPart.PartNumber);
tabPage = CreateTabForm(tabPage, mainPart);
private TabPage CreateTabForm(TabPage Tab, RMA2MainPart MainPart)
int num = tabControl1.TabCount;
Label pnLabel = new Label();
pnLabel.Name = "lbPartNumber" + num;
pnLabel.Text = "Part Number";
pnLabel.Location = new Point(8, 6);
pnLabel.Size = new Size(75, 13);
TextBox pnTextBox = new TextBox();
pnTextBox.Name = "tbPartNum" + num;
pnTextBox.Location = new Point(8, 22);
pnTextBox.Size = new Size(130, 20);
pnTextBox.Text = MainPart.PartNumber;
//Etc. etc. - multiple labels and textboxes added here.........