How to show/hide bizform field(s) per user´s role
This article describes how to show or hide particular bizform´s field(s) per user´s role.
It can be done in the code-behind of your Bizform web part (
CMSWebParts/Bizforms/bizform.ascx.cx), in some appropriate handler (e.g.
Load or
OnPreRender – see bizform´s properties).
You can check if the current user is in the requested role using the following code:
if (CMS.CMSHelper.CMSContext.CurrentUser.IsInRole("CMSEditor", CMS.CMSHelper.CMSContext.CurrentSiteName))
{
//the current user is member of the CMSEditor role
}
Then you can hide/show appropriate control on your bizform. Let´s say that you want to hide some field of TextBox type. You can use this code for this purpose:
Version 5.5 R2 and older versions:
TextBox myField = (TextBox)viewBiz.BasicForm.FieldControls["NameOfAppropriateField"];
myField.Visible = false;
Version 6:
((CMS.FormControls.EditingFormControl)
viewBiz.BasicForm.FieldEditingControls["NameOfAppropriateField "]).Enabled = false;
An alternative approach could be to use FormControl instead of TextBox and manage visibility of this FormControl according to current user´s role.
-bp-
See also: Modifying the code of standard web parts
Applies to: Kentico CMS 4.x, update for Kentico CMS 6.0