Dynamically Added User Control not accessible!

Discussion in 'ASP .Net Web Controls' started by Cathy, Dec 16, 2003.

  1. Cathy

    Cathy Guest

    Hi,

    I am building a dynamic contact form (similar to outlook) and each
    component is different user control e.g Phonenumber, email address.
    This all works fine to display the information.

    The Main User Control Form loads the contact name information then for
    every phone number the contact has, a PhoneNumber user control is
    added to the form and filled with information. The user can alter the
    phoneNumbers (or other information) press the main form Save button
    and all the new info is saved.

    I also have a NEW button which when clicked adds a new empty
    PhoneNumber control to the page and the user can enter information.

    THE PROBLEM:
    After adding a new PhoneNumber control and pressing the save button, I
    am unable to access the new phone number control either by name or
    type from within the Save button function.

    In the Page trace I can see the new control in the controls array
    before I press the Save button, but through VS.NET debug SAVE function
    it appears as an undefined System.Web.UI.Control and I can not access
    the values to save them.

    Is there something else I have to do when adding usercontrols on a
    button click?

    Thanks

    CODE USED TO ADD CONTROL
    =========================
    Control hdrCtl;

    try{
    hdrCtl = LoadControl("PhoneNumber.ascx");
    if (hdrCtl != null)
    {
    ((Presentation.PhoneNumber)hdrCtl).ContactPhoneNumber=new
    Business.PhoneNumber(contactObj.ContactId);
    ((Presentation.PhoneNumber)hdrCtl).ID="newphone";
    phoneHolder.Controls.Add(hdrCtl);
    }
    }
    catch (Exception ex)
    {
    Trace.Write(ex.Message);
    }
     
    Cathy, Dec 16, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Saunders
    Replies:
    0
    Views:
    541
    John Saunders
    Jul 1, 2004
  2. Bennett Haselton
    Replies:
    1
    Views:
    517
    John M Deal
    Nov 8, 2004
  3. =?Utf-8?B?U2FtdWVs?=
    Replies:
    7
    Views:
    1,047
    Scott Allen
    Aug 10, 2005
  4. Replies:
    1
    Views:
    440
    Teemu Keiski
    Jan 3, 2006
  5. Replies:
    1
    Views:
    205
Loading...

Share This Page