[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

adding multiple instance of a user control dynamically

Posted on 2013-06-05
2
Medium Priority
?
213 Views
Last Modified: 2013-06-06
Hi all,

I have a button which when clicked I want to add a user control to a div;

    int count = 0;

    protected void AddSectionButton_Click(object sender, EventArgs e)
    {
        WorkoutSection newSection = (WorkoutSection)LoadControl("~/usercontrols/WorkoutSection.ascx");
        //add the section to the workout and pass to the usercontrol;

        count += 1;

        newSection.sectionName = "NEW SECTION TEST " + count;

        section_container.Controls.Add(newSection);
        
    }

Open in new window


The code work fine fo rthe first click bu tthen doesn't add subsequent instances after I have clicked? any ideas what I am doing wrong here?
0
Comment
Question by:flynny
2 Comments
 
LVL 14

Accepted Solution

by:
Daniel Junges earned 2000 total points
ID: 39222750
you code have to remember all controls added and readd all on every callback
0
 
LVL 13

Expert Comment

by:Jitendra Patil
ID: 39225109
try to add below code in your button click event

 newSection.ClientIDMode = ClientIDMode.AutoID;

so i suppose your code should be as below
int count = 0;

    protected void AddSectionButton_Click(object sender, EventArgs e)
    {
        WorkoutSection newSection = (WorkoutSection)LoadControl("~/usercontrols/WorkoutSection.ascx");
        //add the section to the workout and pass to the usercontrol;

       // newSection.sectionName = "NEW SECTION TEST " + count;
         newSection.ClientIDMode = ClientIDMode.AutoID;
        section_container.Controls.Add(newSection);
       
    }


hope this helps.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Loops Section Overview
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question