创建动态控件的问题 [英] Problem with creation of dynamic controls

查看:69
本文介绍了创建动态控件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为MultiUpload系统动态创建控件.

我的想法是,当按下按钮时,会创建一个新控件,并将其插入面板中,但是该控件会创建一次.

如何创建无限控件?

在网页中:
1个面板
1个按钮

按钮事件:

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:

protected void Button1_Click(...)
{
FileUpload NewFU = new FileUpload();
Panel1.Controls.Add(NewFU);
}

推荐答案

在下面检查此链接参考

动态创建ASP.NET服务器控件并执行通过在ASP.NET和C#.NET中附加事件来进行验证 [ ^ ]

在ASP.NET页面中动态加载Web用户控件 [ ^ ]

在ASP.NET应用程序中为动态创建的控件保留状态 [ ^ ]

投票并接受解决方案
如果这对您有帮助
谢谢
check this link reference below

Dynamic creation of ASP.NET server controls on fly and doing validation by attaching Events in ASP.NET and C#.NET[^]

Loading Web User Controls Dynamically in ASP.NET Pages[^]

Retaining State for Dynamically Created Controls in ASP.NET applications[^]

vote and Accept Solution
If this will help you
thanks


这是一个简单的例子

Here is an simple example

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);
        }
    }
}


这篇关于创建动态控件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆