In global.asax I need to access a checkboxlist which is inside a PropertyControl
Global.asax:
void Instance_PublishedPage(object sender, PageEventArgs e)
{
PageData nySide = EPiServer.DataFactory.Instance.GetPage(e.Page.PageLink);
PropertyData pd = nySide.Property["Siderettigheter"];
//How can I get a handel to the Checkboxlist defind in the propertycontrol?
}
Code from the propertyControl:
public class SideRettigheterControl : EPiServer.Web.PropertyControls.PropertySelectMultipleControlBase
{
public override void CreateEditControls()
{
base.CreateEditControls();
CheckBoxList CheckBoxRoles = this.EditControl;
CheckBoxRoles.DataSource = Extras.Roles();
CheckBoxRoles.DataBind();
CheckBoxRoles.RepeatDirection = RepeatDirection.Vertical;
}
}
The customer want to select among roles. If the role is checked, then
every member whit this role must have read access to the document. If
I get a handel to the checkboxlist then I can update the ACL whit this
roles. I will then use this code:
PageData CurrentPage = EPiServer.DataFactory.Instance.GetPage(e.Page.PageLink);
AccessControlEntry ac = null;
if (roles.Items[i].Selected)
{
if (!CurrentPage.ACL.Exists(roles.Items[i].Value)){
ac = new AccessControlEntry(roles.Items[i].Value, AccessLevel.Read, SecurityEntityType.Role);
CurrentPage.ACL.Add(ac);
CurrentPage.ACL.Save();
}
}
Hi Robert!
You probably don't need to have access to the checkboxlist in the event. Try extracting the value from the property and then split it:
PropertyMultipleValue property = e.Page[Yourpropertyname];
if(property == null || String.IsNullOrEmpty(property.Value))
{
return;
}
string roles = property.Split(',');
foreach(string role in roles)
{
//Add role to acl here
}
//Save Acl
Hope this will help you!
Linus Ekström
EPiServer Development Team
ps. I typed the code freehand so it might have compilation errors. ds.