Creating dynamic management in asp.net

I create a file system control on a click event linKbutton. The first time it creates controls, but if I click the link button a second time, it will not be created. What is the problem? Below 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);
    }
}

and count is a static variable. Please, help.

+1
source share
1 answer

When you create controls dynamically using ASP.NET, you need to recreate the control every time you send the message back, usually you recreate the control on the_Load page. This is most likely the cause of your problem.

+2
source

All Articles