private void LoadControls(Control.ControlCollection Items) { UserAccessRights_DL objUserAccessRightsDL = new UserAccessRights_DL(ConnectionStringClass.GetConnection()); try { foreach (Control var in Items) { if (var.GetType().Equals(typeof(Button))) { if ((!var.Name.Equals("btnExit")) && (!var.Name.Equals("btnClose"))) { UserAccessRights obj = objUserAccessRightsDL.Get(var.Name, CurrentUser.UserRoleID); if (obj != null) { if (obj.Permission == "Active") { var.Visible = true; } else { var.Visible = false; } } } } if (var != null) { LoadControls(var.Controls); } } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }