创建在asp.net中动态控制 [英] creating dynamic control in asp.net

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

问题描述

我要创建一个一个FileUpload控件的LinkBut​​ton 单击事件。第一次是创造了控制,但如果我preSS的链接按钮第二次,这不是创造。什么是什么问题?以下是我的code:

I'm creating a fileupload control on a linKbutton click event. First time it's creating the controls, but if I press the link button second time, it's not creating. What is the problem with that? The following is my code:

protected void LinkButton1_Click(object sender, EventArgs e)
{
    newattach();
}

private void newattach()
{
    int i;
    for (i = 0; i < 2; i++)
    {
        count++;
        FileUpload f1 = new FileUpload();
        f1.ID = "fileupload" + count.ToString();
        f1.Height = 34;
        f1.Width = 212;
        Panel1.Controls.Add(f1);
    }
}

count是一个静态变量。请帮助。

and count is a static variable. Please help.

推荐答案

当您创建控件动态使用ASP.NET你需要在每次回发时重新控制,一般你重新创建的Page_Load控制。这是最有可能您的问题的原因。

When you create controls dynamically with ASP.NET you need to recreate the control every time you post back, generally you recreate the control on Page_Load. That is most likely the cause of your problem.

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

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