Accessing controls added programmatically on postback

前端 未结 3 580
终归单人心
终归单人心 2020-12-20 01:58

On postback: How can I access ASP.NET controls in my code-behind file, which are added programmatically?

I am adding a CheckBox control to a Placeho

3条回答
  •  甜味超标
    2020-12-20 02:11

    You should recreate your dynamic control on postback:

    protected override void OnInit(EventArgs e)
    {
    
        string dynamicControlId = "MyControl";
    
        TextBox textBox = new TextBox {ID = dynamicControlId};
        placeHolder.Controls.Add(textBox);
    }
    

提交回复
热议问题