Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

adding multiple instance of a user control dynamically

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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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