Reputation: 27
have a little problem with this EPIServer error: CS1061: 'System.Web.UI.Control' does not contain a definition for 'CurrentPage' and no extension method 'CurrentPage' accepting a first argument of type 'System.Web.UI.Control' could be found (are you missing a using directive or an assembly reference?)
when i try to access a method with a parameter from my ascx file. The ascx file:
<div id="nav">
<ul role="menu">
<li <%# GetMenuClass(Container.CurrentPage)%> role="menuitem">
<%= GetNewsPage %>
<%--<a href="#">News</a>--%>
</li>
<li <%# GetMenuClass(Container.CurrentPage) %> role="menuitem">
<%= GetClientPage %>
<%--<a href="#">Clients</a>--%>
</li>
</ul>
</div>
The method in codebehind:
protected string GetMenuClass(PageData page)
{
if (page.IsSelected(CurrentPage))
{
return "class=\"menu-item selected\"";
}
return "class=\"menu-item\"";
}
what i want to achieve is something like this (if news page is selected):
<div id="nav">
<ul role="menu">
<li class="menu-item selected" role="menuitem"> News </li>
<li class="menu-item" role="menuitem">
<a href="#">Clients</a>
</li>
</ul>
</div>
</nav>
I'm greatful if some one can help.
Upvotes: -1
Views: 1739
Reputation: 949
I note you're using a binding syntax expression ( a <%#) and make use of Container, so I'm presuming this in a databound control like a repeater?
If it is, try amending your call to GetMenuClass to the following
GetMenuClass((PageData)Container.DataItem)
assuming you have bound a collection of PageData objects to the repeater
Upvotes: 1
Reputation: 184
It looks like the type of Container property is System.Web.UI.Control. I'm not sure what is the Container is your case, but it looks like you need to cast it to corresponding specific type, like EPiServer.UserControlBase, EPiServer.PageBase or EPiServer.Web.WebControls.PageControlBase. These types contain CurrentPage property which is PageData.
Upvotes: 4