Error with asp:Repeater in MasterPage template
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:
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.
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();