CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2002
    Location
    Sioux Falls, SD, USA
    Posts
    40

    Question Custom Control - accessing controls

    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!!!
    Do what thou wilt, shall be the whole of the law.

  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868
    Your usercontrol containing the textboxes needs to have properties to allow access to the values or the textboxes need to be public.

  3. #3
    Join Date
    Dec 2002
    Location
    Sioux Falls, SD, USA
    Posts
    40
    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!
    Last edited by Dreamon; March 28th, 2003 at 05:30 PM.
    Do what thou wilt, shall be the whole of the law.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured