Click here to Skip to main content
15,895,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'm tryin create controls dynamically for do an MultiUpload system.

My idea is when the button is pressed, a new control creates, and insert inside a panel, but the control creates once.

How I can create unlimited controls?

In the WebPage:
1 Panel
1 Button

The Button Event:
C#
protected void Button1_Click(...)
{
FileUpload NewFU = new FileUpload();
Panel1.Controls.Add(NewFU);
}
Posted
Updated 10-Mar-12 16:04pm
v2
Comments
Sergey Alexandrovich Kryukov 10-Mar-12 21:58pm    
You need to write the code doing it. What did you try and what's the problem?
--SA
TANicox 10-Mar-12 22:05pm    
Ready, I'm inserted the code

Here is an simple example

C#
using System;
using System.Windows.Forms;

namespace CreateControls
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Form form = new Form() { Text = "CreateControls" };
            // Create a control to hold your dynamic one's
            // We use a Panel here
            Panel panelPlaceHolder = new Panel() { Dock = DockStyle.Left };
            // ... Dock it to the Form somewhere
            form.Controls.Add(panelPlaceHolder);
            // ... Create a Button to add new controls
            Button buttonAddControl = new Button() { Text = "Create Control", Dock = DockStyle.Top };
            form.Controls.Add(buttonAddControl);
            buttonAddControl.Click += delegate(object sender, EventArgs e)
            {
                // Create a new Control
                // ... maybe a Label? (could be any Control)
                Label label = new Label() { Text = "I'm new", Dock = DockStyle.Top };
                // add it to your Container
                panelPlaceHolder.Controls.Add(label);
            };

            // Run the example Form
            Application.Run(form);
        }
    }
}
 
Share this answer
 
Comments
TANicox 10-Mar-12 22:20pm    
Doesn't work. I tryied but, nothing.
Remember I'm working with ASP and no with WinForms
johannesnestler 11-Mar-12 7:35am    
Sorry, you changed your question while I was writing it. I thought I just post it anyway - It should give you an idea of the pattern (your questione sounded like beginner question at first). So I provided a runnable example. Do you still need help on that?
TANicox 11-Mar-12 12:50pm    
Yes, I couldn't do yet. Can you provide to me an example?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900