I've cobbled this together from various places. What i'm trying to do is show or hide a custom page type based on a user role, and a option from the admin side (visibiltyType).
So far it seems to be working, but i'm not sure of my conditional statement syntax is the best. C# is not my strong point.
Here's my transformation:
<script runat="server">
public bool visibility;
public string visiblityType;
protected override void OnDataBinding(EventArgs e)
{
visiblityType = Eval("Visibility").ToString();
if( CMS.Membership.MembershipContext.AuthenticatedUser.IsInRole("scona-cms_resources_branchdirectors", CMS.SiteProvider.SiteContext.CurrentSiteName) && visiblityType == "ncp" ){
alert.Visible = true;
}
if( CMS.Membership.MembershipContext.AuthenticatedUser.IsInRole("scona-cms_resources_salesreps", CMS.SiteProvider.SiteContext.CurrentSiteName) && visiblityType == "ncp" ){
alert.Visible = true;
}
if( CMS.Membership.MembershipContext.AuthenticatedUser.IsInRole("scona-kff-headoffice", CMS.SiteProvider.SiteContext.CurrentSiteName) && visiblityType == "ncp" ){
alert.Visible = true;
}
if( CMS.Membership.MembershipContext.AuthenticatedUser.IsInRole("scona-cms_resources_partnernetwork", CMS.SiteProvider.SiteContext.CurrentSiteName) && visiblityType == "cp" ){
alert.Visible = true;
}
if (visiblityType == "both"){
alert.Visible = true;
}
}
</script>
<asp:placeholder id="alert" runat="server" Visible="false">
<li><%# Eval("Visibility") %> | <%# Eval("AlertDate") %> - <%# Eval("AlertTitle") %> <%# IfEmpty(Eval("AlertCopy"),"", " <a href='" + GetDocumentUrl() + "'>Read More</a>") %></li>
</asp:placeholder>