FindControl can't locate my dynamically added control
<p>I have a repeater that lists customer items, one of which is a button for more information.  When the user clicks that button, a user control appears immediately below it.  I'd like for the user control to then close when the button is clicked again.  I initially toggled visibility server-side, but I now can't use this because the user control needs to be loaded on the button click due to parameters that need to bepassed through.  I also can't used show and hide by jquery because that would involve downloading all the data first for the whole page which could make the page too cumbersome.</p>

<p>So currently in each repeater I have a linkbutton with command arguments and an OnCommand event which fires this event:</p>

<pre><code>protected void uxPolicyDocsButton_Command(object sender, CommandEventArgs e)
    {
        //Find Policy Summary control within repeater item in order to toggle visibility

        LinkButton button = sender as LinkButton;
        if (button != null)
        {
            RepeaterItem ri = button.Parent as RepeaterItem;

            if (ri != null)
            {
                PlaceHolder policySummaryPlaceHolder = (PlaceHolder)ri.FindControl("uxPolicySummaryPlaceHolder");                    
                Control policyDocuments = (Control)PolicySummaryPlaceHolder.FindControl("uxPolicyDocumentsControl");


                foreach (Control c in policySummaryPlaceHolder.Controls)
                {
                    //FindControl action goes in here.  Have stepped through though and it doesn't appear
                }

                if (policyDocuments != null)
                {
                    policySummaryPlaceHolder.Controls.Remove(policyDocuments);
                }
                else
                {
                    policyDocuments uxPolicyDocumentsControl = (PolicyDocuments)LoadControl("~/Controls/Home/PolicyDocuments.ascx");
                    uxPolicyDocumentsControl.PolicyNumber = button.CommandArgument;
                    policySummaryPlaceHolder.Controls.Add(uxPolicyDocumentsControl);
                }
            }
        }
    }
</code></pre>

<p>My plan for the toggle was that if the PolicyDocuments control was null, then load the control, and if not then remove the control, but it always came back null.  It did load the control correctly though.</p>

<p>Here is the section of the repeater:</p>

<pre><code>&lt;ItemTemplate&gt;
                    &lt;tr&gt;
                        &lt;td&gt;
                            &lt;%#Eval("StartDate","{0:d}")%&gt;
                        &lt;/td&gt;
                        &lt;td class="center-cell-ctrl"&gt;
                            Postcode:&lt;br /&gt;
                            &lt;%#Eval("Postcode")%&gt;
                        &lt;/td&gt;
                        &lt;td id='&lt;%#Eval("PolicyNumber")%&gt;' class="button-cell"&gt;                                
                            &lt;asp:LinkButton ID="uxPolicyDocsButton" CommandName="PolicyNumber" CommandArgument='&lt;%#Eval("PolicyNumber")%&gt;' OnCommand="uxPolicyDocsButton_Command"  runat="server" Visible="false"&gt;Policy&lt;br /&gt;Documents&lt;/asp:LinkButton&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;asp:PlaceHolder ID="uxPolicySummaryPlaceHolder" runat="server"&gt;&lt;/asp:PlaceHolder&gt;
                    &lt;asp:PlaceHolder ID="uxPolicyDocumentsPlaceHolder" runat="server"&gt;&lt;/asp:PlaceHolder&gt;

        &lt;/ItemTemplate&gt;
</code></pre>

<p>I've had a look around for people who have had similar problems, and a common answer is that you need to load controls in the Page_Init event.  Does that mean that this way won't work?  Any ideas for an alternative if this is the case?</p>

<p>Many thanks</p>
