Hi,
I want to call a bunch of data formatting methods in an external class (method 3 below) so that I can reuse this in multiple UI displays.
I need help with method 3 in creating a static Helper class with how to pass the appropriate DNN context to the static method.
Code below will display the Email field if the user is an admininstrator and ... if he is NOT.
Method 1:
<%# (PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName) == true ? Eval("RsvpEmail") : "...")%>
Method 2:
<%# DisplayEmail(Eval("RsvpEmail"))%>
// codebehind method, requires that you put this code in each User Control
public string DisplayEmail ( object oEmail )
{
// if Admin is logged in show Full Email else show ...
return ( (PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName) == true ? oEmail.ToString() : "...");
}
Method 3: call method in external class
This is preferable as we can abstract the Display logic to this external class
and not have UI display business rules based on security in the aspx page
<%# DNNRsvpUtil.DisplayEmail(Eval("RsvpEmail"), ???? )%>
public static class DNNRsvpUtil
{
public static string DisplayEmail ( object oEmail, ??? )
{
// this won't work until we pass the correct DNN context objects in
return ( (PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName) == true ? oEmail.ToString() : "...");
}
}
Thanks, Paul