Click to See Complete Forum and Search --> : Custom Control - accessing controls


Dreamon
March 27th, 2003, 03:55 PM
Hi all!

I hope I can describe my situation/problem in a understandable fashion. Here goes:

I have a default.aspx page that has 3 user controls on it at all times. Now, one of the user controls (Page5.ascx) actually uses yet another user control (EmpRec.ascx), which has a table with some textboxes in it. By default, the Page5 control only has ONE EmpRec control. However, I want the user to be able to add as many of the EmpRec controls as he/she wants.
So far I have it covered. However, its when I am submit this page and save the data (with n number of EmpRec controls) the problem occurs. How the heck to I get the data from the textboxes? I mean, they all derive from the same user control, hence: textboxes with the same id. How do I differ the different textboxes from eachother?

I'm not sure if this was anything close to being clear. Please let me know if you don't understand my problem, and I'll try to make myself a little clearer.

Thanks!!!

DSJ
March 28th, 2003, 08:22 AM
Your usercontrol containing the textboxes needs to have properties to allow access to the values or the textboxes need to be public.

Dreamon
March 28th, 2003, 04:23 PM
Originally posted by DSJ
Your usercontrol containing the textboxes needs to have properties to allow access to the values or the textboxes need to be public.

Ok, that is cool and everything, BUT...... how do I reference the dynamically added usercontrols.

for (int i=1; i<=(int)Session["Count"] + 1; i++)
{

sControlName = "oEmpRecord" + i.ToString();

Control oControl = (Control)this.Parent.FindControl("oPlcHldr");
Control oControl2 = (Control)oControl.FindControl(sControlName);

TextBox oText = (TextBox)oControl2.FindControl("oTextEmployer");
}

I have tried this code, but I doesn't work. I get a reference error.

PS. The code listed here is run from a different usercontrol on the same page.

Hope somebody can help me out.

Thanks!