In my application I am generating some controls dynamically. On telerik menu control when I click I want to remove those controls and add new controls. I am using the following code. It is removing the controls but only one control per click. Why this code is not removing all the controls at one time?
private void radMenuItem3_Click(object sender, EventArgs e)
{
foreach (Control ctrl in rpvRecord.Controls)
{
ctrl.Dispose();
}
}
The issue is that you are deleting the control out of the collection that you are iterating through, which causes a change in the collection and causes the loop to fail. I would suggest using a different style of loop to accomplish this. For example:
Hope this helps!