Controles de enlace de datos dentro de CompositeControl

I have created a CompositeControl that is essentially a wrapper for a MultiView, but if I try to use any databound controls such as GridView or FormView inside the View, I get the error:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

I've stripped the class down to the bare minimum and I'm still getting the error. The class looks like this:

[DefaultProperty("Pages"), ParseChildren(true, "Pages"), ToolboxData("<{0}:TestTabs runat=\"server\"></{0}:TestTabs>")]
public class TestTabs : CompositeControl {

    private MultiView _multiViewControl;

    private Collection<View> _pages;
    public Collection<View> Pages {
        get {
            if (_pages == null) _pages = new Collection<View>();
            return _pages;

    protected override void CreateChildControls() {
        _multiViewControl = new MultiView();
        foreach (View page in Pages) { _multiViewControl.Views.Add(page); }
        if (_multiViewControl.Views.Count > 0) _multiViewControl.ActiveViewIndex = 0;



And the markup is as follows:

<cc:TestTabs ID="testTabs" runat="server">
    <asp:View runat="server">
        <asp:FormView ID="fvTest" runat="server">
                <asp:Label ID="lblTest" runat="server" Text='<%#Eval("TestField")%>' />

If I move the FormView outside the CompositeControl, it databinds with no problem. Also If I use a standard MultiView it works fine.

Any ideas? Thanks in advance (first post, so apologies if I've missed any info)

Edit: To make things even more strange, if I extract the FormView into a separate ascx UserControl and put that inside the View, it works!

preguntado el 08 de noviembre de 11 a las 11:11

1 Respuestas

Puedes heredar CompositeDataBoundControl insted de CompositeControl

Respondido el 06 de diciembre de 11 a las 15:12

Ah interesting, didn't think of that. Unfortunately I've since found a better way of doing it with the Ajax TabContainer but if I find time I will test this out. Thanks - RossJ

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.