Remove control from another control

Y

Yourself

I have the following .aspx code:

<%@ Page Language="vb" AutoEventWireup="false" Explicit="True"
Inherits="Whatever.DefaultPage" CodeFile="Default.aspx.vb" %>
<%@ Register TagPrefix="whatever" TagName="something"
Src="~/Whatever/Whatever.ascx" %>
<asp:placeholder id="fred" runat="server"></asp:placeholder>
<whatever:something id="something" runat="server" />

the Default.aspx.vb code adds some controls to the 'fred' placeholder in the
Page_Init method.

I want to remove all of the controls added to the 'fred' placeholder, within
my user control 'whatever:something'.

My Whatever.ascx.cs Page_Init method looks like this:

// get the fred placeholder (this line works and returns a placeholder which
!= null)
System.Web.UI.WebControls.PlaceHolder fred =
(PlaceHolder)Parent.Page.FindControl("fred");

// clear all of freds controls
if (fred != null)
{
fred.Controls.Clear();
}

The fred.Controls.Clear() doesn't work, all of the controls that fred has
added (within Default.aspx.vb) are still there :(

Is it something to do with the order in which the Page_Init methods are
called? Are they called in any specific order?

Any ideas? Please help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top