Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Dynamically Added User Control not accessible!

Reply
Thread Tools

Dynamically Added User Control not accessible!

 
 
Cathy
Guest
Posts: n/a
 
      12-16-2003
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).ContactPhoneNum ber=new
Business.PhoneNumber(contactObj.ContactId);
((Presentation.PhoneNumber)hdrCtl).ID="newphone";
phoneHolder.Controls.Add(hdrCtl);
}
}
catch (Exception ex)
{
Trace.Write(ex.Message);
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically added user control Chris ASP .Net 9 04-01-2007 06:34 PM
Dynamically added user control throws object not set andyrich_1@hotmail.com ASP .Net 1 01-03-2006 01:58 PM
reference web control in dynamically added user control, ASP.NET 2 =?Utf-8?B?U2FtdWVs?= ASP .Net 7 08-10-2005 02:12 AM
Handle Event of Dynamically Added User Control Jon B ASP .Net 5 04-30-2005 12:33 PM
how come user control added to page doesn't get added to codebehind file? Bennett Haselton ASP .Net 1 11-08-2004 09:26 PM



Advertisments