How do I remove my dynamically added textbox?

后端 未结 2 1584
终归单人心
终归单人心 2021-01-22 14:11

here in my codebehind I have created a way to add asp:Textbox dynamically

Create button action to create text field

List contr         


        
2条回答
  •  抹茶落季
    2021-01-22 14:48

    You can remove textbox from your placeholder like below:

    protected void Remove(object sender, EventArgs e)
    {
        foreach (Control control in PlaceHolder1.Controls)
        {
            //Here you need to take ID from ViewState["controlIdList"]
            if (control.ID == "TakeIDFromControlListsID")
            {
                Controls.Remove(control);
                control.Dispose();
            }
        }
     }
    

提交回复
热议问题