Solved

adding multiple instance of a user control dynamically

Posted on 2013-06-05
2
200 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 500 total points
ID: 39222750
you code have to remember all controls added and readd all on every callback
0
 
LVL 12

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

896 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now