Error with asp:Repeater in MasterPage template

Posted by Community Admin on 03-Aug-2018 16:37

Error with asp:Repeater in MasterPage template

All Replies

Posted by Community Admin on 31-Mar-2011 00:00

I have a MasterPage template that uses an aspnet Repeater control.  This works fine when viewing the page directly; however, when editting the page in Sitefinity, I get the following error:

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

Here is the markup:

<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <div>
        <asp:Repeater ID="ItemRepeater" runat="server">
            <HeaderTemplate>
                <ul>
            </HeaderTemplate>
            <ItemTemplate>
                <li class="Item"><a href="<%# Eval("Url") %>"><%# Eval("Title") %></a></li>
            </ItemTemplate>
            <FooterTemplate>
                </ul>
            </FooterTemplate>
        </asp:Repeater>
    </div>
    <div id="contentwindow">
        <div id="Content">
            <div id="ContentBlockMain">
                <asp:ContentPlaceHolder ID="ContentBlock" runat="server" />
            </div>
        </div>
    </div>

The ItemRepeater.DataBind() is being invoked in Page_Load() of the MasterPage.

Any idea what could be causing this?  Is there a workaround, or from the MasterPage codebehind, can I detect if the page is being displayed through Sitefinity and act accordingly?

Thanks,
-Chris B.

Posted by Community Admin on 05-Apr-2011 00:00

Hello Chris Bryant,

There are control extensions - ControlExtensions

IsDesignMode - static method which determines whether the control is in Sitefinity design mode - you  are editing a page. There are also

IsPreviewMode- determines whether the control is in Sitefinity preview mode.

IsBackend -determines whether a control instance is in backend.

 

sample

protected override void OnPreRender(EventArgs e)
    
 
        base.OnPreRender(e);
 
        if (this.IsDesignMode() && !this.IsPreviewMode())
        
            this.Controls.Clear();
        
 
    

You can use one of the methods below to disable the control binding/rendering and suppress the error you are getting.

Kind regards,
Ivan Dimitrov
the Telerik team

This thread is closed