How do I access multiple user control whilst user control is in placeholder for computing sum of textboxes that are in each user control row?

I have a user control with two textboxes - tbQuantity and tbTotal. The control is placed in a placeholder. Their is an addbutton to add multiple rows of controls. I want to accomplish the following...tbTotal will compute the sum of all the values in tbQuantity. So if I have 3 rows of controls I will need on the ending row's tbTotal to have computed the values of tbQuantity in the ending row and also the preceding 2 rows values of tbQuantity. So if their is a way for the tbTotal to have a rolling sum in each row or if all of the tbTotals will have the same value (the value of the ending row's tbTotal) that is fine also. I just need to know how and where to access the textboxes so I can write the code... The usercontrol page or the aspx page... I don't know where to start.
/***************User Control********************/
 
<table cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td valign="middle">
            <asp:DropDownList ID="ddSet" runat="server" 
                onselectedindexchanged="ddSet_SelectedIndexChanged">
            </asp:DropDownList>
            &nbsp;
            <asp:DropDownList ID="ddSubSet" runat="server">
            </asp:DropDownList>
            &nbsp;Quantity:<asp:TextBox ID="tbQuantity" runat="server" CssClass="textbox" 
                ontextchanged="tbQuantity_TextChanged"></asp:TextBox>
            &nbsp;MEPRS Total:<asp:TextBox ID="tbTotal" runat="server" CssClass="textbox"></asp:TextBox>
            <asp:ImageButton ID="ibtDeleteItems" runat="server" ImageUrl="~/Images/delete.gif"
                AlternateText="Delete Item" OnClick="ibtDeleted_Clicked" />
        </td>
    </tr>
</table>
/**************Placeholder********************/ 
 
<asp:PlaceHolder ID="phItems" runat="server"></asp:PlaceHolder>
<input type="submit" id="btnAddItem" name="btnAddItem" value="AddItem" runat="server" />
 
/********************Adding New Control to Placeholder******************************/
 
       private void Add_Items()
    {
        foreach (string ctl in Page.Request.Form)
        {
            if (ctl == "btnAddItem")
            {
                ctlCount2.Value = (Convert.ToInt16(ctlCount2.Value) + 1).ToString();
            }
        }
 
        // clear all dropdown and textbox controls
        phItems.Controls.Clear();
 
        int controlId = 1;
 
        for (int i = 0; i < Convert.ToInt16(ctlCount2.Value); i++)
        {
            ASP.uc_Items myUserControl = (ASP.uc_Items)LoadControl("uc_Items.ascx");
 
            while (InDeletedList2("ucItems" + controlId.ToString()))
            {
                controlId += 1;
            }
 
            myUserControl.ID = "ucItems" + controlId.ToString();
            myUserControl.RemoveUserControl += new EventHandler(HandleRemoveUserControl2);
            //myUserControl.RemoveUserControl += this.HandleRemoveUserControl;
            phItems.Controls.Add(myUserControl);
            controlId += 1;
        }
    }

Open in new window

mjoseph23Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ashley BryantSenior Software EngineerCommented:
I've done something similar to what you're doing.  Basically, you loop through the controls in the placeholder and verify their type.  If you look at this code snippet, you should be able to figure out what I did and do something similar to apply the logic to your own site.

formActivities is the placeholder.
activityform.ascx was the user control and it's type was ASP.activityform_ascx
I reference the controls within the user control by index to speed things up a bit

if (formActivites.HasControls())
{
    foreach (Control ctl in formActivites.Controls)
    {
        if (ctl.GetType().ToString() == "ASP.activityform_ascx")
        {
            RadioButtonList cbl = (RadioButtonList)ctl.Controls[5];
            foreach(ListItem i in cbl.Items){
                if (i.Selected)
                {
                    String strSql = String.Format("INSERT INTO EventActivityTimesAttendees (AttendeeID, SlotID) VALUES ({0}, {1})", AttendeeID, i.Value);
                    _db.InsertNoReturn(strSql, null, false);
                }
            }
        }
    }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mjoseph23Author Commented:
Ok. I need to be able to do this code in an event. Preferrably when the text is changed in tbQuantity textbox, then I want to use the code to check the values of each control's tbQuantity textbox and put it in the tbTotal textbox
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.