Remove statically added controls at runtime
<p><strong>The Scenario:</strong> I have an asp.net website where I show a div popup on page load for taking a few user details. When a user inputs the details, or closes the popup, I set up a flag cookie so that the popup is not displayed again for the user. The div is in the MasterPage so that it is displayed no matter on which page a user lands first time. The div contains an UpdatePanel which has all the controls required for taking the details. This whole functionality is working fine.</p>

<p><strong>The Problem:</strong> Now this div popup is not showing(by setting display:none) on subsequent postbacks(which I want), but the html markup is still loading with the page unnecessarily adding to the page size. What I would idealy want to do is: Check if flag cookie is set. If no, show the popup, else remove the popup's markup from the page.</p>

<p>Now since the div is not a server control, I cannot possibly remove it and the all the controls inside it. So, I thought of removing the UpdatePanel from the page:</p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies["flag"] != null)
        {
            if (Page.Controls.Contains(updpnl_contact))
            {
                Page.Controls.Remove(updpnl_contact);
                updpnl_contact.Dispose();
            }
        }
    }
</code></pre>

<p>But I guess this tends to work with dynamically added controls only, and since the control is added at Design Time, it is not being removed.</p>

<p>Is there any way I can achieve this?</p>
