I've created a page property of Boolean type, and I try to check the state before rendering some text on a page.
As long as the value is "true" there's no problem, but since the value "false" is not stored in the database I need to handle the Null-value in some way.
Here's what I do, and it works fine on a page - it's just that I want to do this in a PageList, and instead of calling CurrentPage["NotScheduled"] I want to call Container.Currentage["NotScheduled"] in an ItemTemplate. I just can't make it work.
The HTML part:
<%if (scheduledstate(currentpage)="=" "false") { %>
<% } %>
%>%if>
The CodeBehind:
protected string ScheduledState(PageData page)
{
if (page["NotScheduled"] != null)
{
_ScheduledState = page["NotScheduled"].ToString();
return "true";
}
else
{
return "false";
}
}
That is, the following doesn't work, it tells me "The type or namespace name 'Container' could not be found (are you missing a using directive or an assembly reference?)"
<%if (ScheduledState(Container.CurrentPage) == "false") { %>
Why not do it like this and save yourself mixing code with html so much!
<%#ScheduledState(Container.CurrentPage)%> (html page calls a function, passing the Container.CurrentPage to the code behind)
then in code behind:
protected string ScheduledState(PageData page)
{
//your logic should be done here and the value you want to display sent back to the browser...
if (page["NotScheduled"] != null)
{
return page["whatever"].ToString();
}
else
{
return string.empty;
}
}
That's actually a good way to go after all - although I would have preferred to be able to use EPiServer properties in the aspx page instead och putting strings together in the Code Behind.
But anyway - it helped me! Thanx!
<%if (scheduledstate(currentpage)="=" "false") { %>
<% } %>
%>%if>
The CodeBehind:protected string ScheduledState(PageData page) { if (page["NotScheduled"] != null) { _ScheduledState = page["NotScheduled"].ToString(); return "true"; } else { return "false"; } }