How to Add/Remove controls dynamically in ASP.NET AJAX Update Panel

Waqas Anwar
14 September 2010
12773 Views

You have implemented AJAX asynchronous postback using ASP.NET AJAX Update Panel and you want to clear all controls in Update Panel after postback you can write following:

UpdatePanel1.ContentTemplateContainer.Controls.Clear();
If you want to add controls in UpdatePanel you can write:
Label lblMessage = new Label();
lblMessage.Text = "Thank You";

UpdatePanel1.ContentTemplateContainer.Controls.Add(lblMessage);

Finally you can call Update method of UpdatePanel

UpdatePanel1.Update();