Dynamically Added User Control not accessible!

C

Cathy

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);
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top