How to find a control inside DynamicDetailContainer Layout T

Posted by Community Admin on 04-Aug-2018 19:47

How to find a control inside DynamicDetailContainer Layout Template

All Replies

Posted by Community Admin on 28-Jan-2013 00:00

I am trying to get access to a literal control inside of the Layout Template of a DynamicDetailContrainer object.  Below is the code that I typically see but for some reason when I access the Controls property and access the 0th item in the index it returns NULL.

var c = (Literal)this.detailContainer.Controls[0].FindControl("MyLiteralControl");

The markup in my ascx file for the widget templates starts off with the following code.

<sf:DynamicDetailContainer id="detailContainer" runat="server">
    <LayoutTemplate>
        <asp:Literal ID="MyLiteralControl" runat="server" Text="Testing 1 2 3"></asp:Literal>
        <!--  more stuff -->
    </LayoutTemplate>
</sf:DynamicDetailContainer>

What am I doing wrong?  Any help would be appreciated.  Thank you.


Thanks,
Craig

Posted by Community Admin on 28-Jan-2013 00:00

Found the answer!

Before you can look at the Controls property of the DynamicDetailContainer you need to bind to the Databound event and access it from within the DataBound event.

First, I overrode the OnInit event and then setup an event to call on DataBound of the DynamicDetailContainer.

protected override void OnInit(EventArgs e)
    base.OnInit(e);
    this.detailContainer.DataBound += detailContainer_DataBound;

 

Second, inside of the DataBound event handler I can now access the Controls property of the DynamicDetailContianer.

protected void detailContainer_DataBound(object sender, EventArgs e)
    var c = (Literal)this.detailContainer.Controls[0].FindControl("MyLiteralControl");
 
    //  ... more code ...

 

Hopfully this will be helpful for others that are having this same issue.

 

Thanks,
Craig

This thread is closed