I have a user setup form that contains several RadButtons for the individual permissions (checkboxes). The RadButtons are created at runtime on page init then added to a fieldset:
This part of the code works great. The permissions are added and displayed appropriately. The problem is now accessing the controls on postback. Since they were added at runtime and can be varied in number I need to iterate all possible permissions checked. The original plan was to get any Request.Form elements that matched the ID pattern of "Permission_" like so:
While this call does successfully retrieve the permissions, the information returned is a serialized version of the RadButton control:
So, how can I deserialize this back into a RadButton to be able to interpret the checked status of each of my permissions? I know I could manually breakdown the string, but that seems like a workaround at best.
Thanks.
Tom
var availablePermissions = Permissions.AllPermissions(PermissionCategory.Client);foreach (var permission in availablePermissions){ //create the permission checkbox var checkbox = new RadButton { AutoPostBack = false, ToggleType = ButtonToggleType.CheckBox, ButtonType = RadButtonType.ToggleButton, ID = "Permission_" + permission.Name, Value = permission.Name, ToolTip = permission.Description, Text = permission.DisplayName, Checked = workUser.HasPermission(permission) }; PermissionFieldSet.Controls.Add(checkbox);}This part of the code works great. The permissions are added and displayed appropriately. The problem is now accessing the controls on postback. Since they were added at runtime and can be varied in number I need to iterate all possible permissions checked. The original plan was to get any Request.Form elements that matched the ID pattern of "Permission_" like so:
public bool SaveOrUpdateUser(){ /* Various other user setup fields */ //get all form fields that contain the "Permission_" identifier var permissions = Request.Form.AllKeys.Where(key => key.Contains("Permission_")).Select(key => Request.Form[key]).ToList();}While this call does successfully retrieve the permissions, the information returned is a serialized version of the RadButton control:
{\"text\":\"ButtonText\",\"value\":\"ButtonValue\",\"checked\":true,\"target\":\"\",\"navigateUrl\":\"\",\"commandName\":\"\",\"commandArgument\":\"\",\"autoPostBack\":false,\"selectedToggleStateIndex\":0,\"readOnly\":false}So, how can I deserialize this back into a RadButton to be able to interpret the checked status of each of my permissions? I know I could manually breakdown the string, but that seems like a workaround at best.
Thanks.
Tom