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


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();

 

 

About author


User avatar

Waqas Anwar

Founder of EzzyLearning.com, Senior Consultant, Microsoft .NET and Web Technologies

Comments