1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Error with asp:Repeater in MasterPage template

Error with asp:Repeater in MasterPage template

2 posts, 0 answered
  1. Chris Bryant
    Chris Bryant avatar
    33 posts
    Registered:
    07 Jul 2009
    31 Mar 2011
    Link to this post
    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.

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    05 Apr 2011
    Link to this post
    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

2 posts, 0 answered