Dynamically added controls aren't magically re-added on postback. Rather,
they need to be recreated in order to have their values re-populated from
viewstate. Normally, one would save information for what needs to be
reloaded in the viewstate...
your for statement..
passenger.BindControl
end for
ViewState.Add("NumberOfPassenbers", Master.PartyCtrl.Adults.Count);
if page.ispostback and Viewstate("NumberOfPassengers") is not nothing then
for (int x = 0; x < (int)ViewState("NumberOfPassengers"); ++i)
//re-create the control and re-add it to the panel
next
that's a good mix of vb.net and c#
As an alternative you can use Denis Bauer's (free)
DynamicControlsPlaceholder:
http://www.denisbauer.com/ASPNETCont...aceholder.aspx
Karl
--
http://www.openmymind.net/
"OJ" <of****@gmail.com> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.com...
Hi,
I have added code to run on a button click event which adds
usercontrols to an asp:Panel control held in a contentplaceholder
defined by the masterpage.
for (int x = 0; x < (Master.PartyCtrl.Adults ); x++)
{
ASP.usercontrols_passenger_ascx passenger = new
ASP.usercontrols_passenger_ascx();
this.pnlAdults.Controls.Add(passenger);
passenger.ID = "passAd" + x.ToString();
passenger.RoomSource = this.SABSRooms1.Rooms;
passenger.BindControls();
}
This works nicely and displays as many or as few of the Passenger
control as required. However, when the passenger has filled in various
bits of info and clicks the submit button again I cannot find these
controls that have been added to retrieve their value. Can anyone help?
O