I have gone through your code, the issue here is, every time it is a postback, and child control loops through parent number of times, so for every parent control it is getting added. This is a bug in the code, essentially we shouldn't be repeating the payments creation as many number of times webusercontrol exist on the page.
consider the following code.
public partial class WebUserControl : System.Web.UI.UserControl
{
Payment p1;
public delegate void addPaymentHanler(object sender, EventArgs e);
public event addPaymentHanler addPayment;
public void addPaymentHandler(object sender, EventArgs e)
{
}
public void btn_addClick(object sender, EventArgs e)
{
if (this.addPayment != null)
{
this.addPayment(sender, e);
}
}
I have added addPayment event for WebUserControl, which will be fired on everyclick btnAdd1 on the WebUserControl, and the handler for this can be hooked from the default.aspx.cs page. In AddAndRemoveDynamicControls() method of _Default in for loop
for (int i = 0; i <= (Convert.ToInt16(ltlCount.Text) - 1); i++)
{
DynamicUserControl = (WebUserControl)LoadControl("WebUserControl.ascx");
.
.
.
add the following line,
DynamicUserControl.addPayment += new WebUserControl.addPaymentHanler(DynamicUserControl_addPayment);
.
.
}
and have the event handler to add the payment to the current webusercontrol control
void DynamicUserControl_addPayment(object sender, EventArgs e)
{
}
Hope this helps.