Solved

adding multiple instance of a user control dynamically

Posted on 2013-06-05
2
203 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reading the Web.Config using IIS 7.5? 4 35
Where did System.Data.Objects go? 2 23
Need to start a web service from Visual Studio 2015 Pro 2 21
C# Gridview 1 27
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

815 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

10 Experts available now in Live!

Get 1:1 Help Now