Search code examples
c#asp.netuser-controlsdevexpressformview

Access userControl inside formView footer template from code behind


I have the following code:

   <asp:FormView runat="server">
      <ItemTemplate>
      </ItemTemplate>
      <FooterTemplate>

            <div>
                <hr/>
                <uc1:Footer runat="server" ID="Footer" />
            </div>

        </FooterTemplate>

    </asp:FormView>

In Footer.ascx I have:

<dx:ASPxLabel ID="lbl" runat="server" Font-Italic="True" Font-Size="10px"></dx:ASPxLabel>

I want to access my user control FooterDetail from the code behind to set lbl value.

How can'I do this.

Thanks.


Solution

  • First you need to provide a property that returns the Label of the UserControl or better just it's Text. Then you can use the FormView's FooterRow property and FindControl to get it:

    var uc = (UserControlTypeName)FormView1.FooterRow.FindControl("Footer");
    uc.Value = "New Value";
    

    Here's the property in your UserControl:

    public string Value
    {
        get { return lbl.Text; }
        set { lbl.Text = value; }
    }