Enable form fields with ReadWriteAuthorization1

Enable form fields with ReadWriteAuthorization1

Old forum URL: forums.lhotka.net/forums/t/5414.aspx


Warren posted on Tuesday, September 16, 2008

Howdy,

I am using ReadWriteAuthorization1 to reset individual controls on my forms. My understanding is that it will disable individual controls if a user doesn't have access to an individual property that a control is bound to. 

I would like my form fields to be disabled when the form first loads.  They will be empty. Can ReadWriteAuthorization1 be used to enable form fields when a user *does* have access to the control binding property?

Otherwise, I need to reference the individual fields in my  code to enable/disable them like below.

Thanks in advance.

 

Region " Class Methods "

Private Sub ApplyAuthorizationRules()

Dim canEdit As Boolean = Client.CanEditObject

Dim allowEdit As Boolean = mClient IsNot Nothing

' enable/disable buttons

Me.ButtonNew.Enabled = canEdit

If allowEdit Then

Me.ButtonSave.Enabled = canEdit And mClient.IsSavable()

Me.ButtonDelete.Enabled = canEdit And Not mClient.IsDirty

Else

Me.ButtonSave.Enabled = False

Me.ButtonDelete.Enabled = False

End If

' enable/disable controls

Me.TextBoxFullName.Enabled = allowEdit

Me.TextBoxAddress1.Enabled = allowEdit

Me.TextBoxAddress2.Enabled = allowEdit

Me.TextBoxAddress3.Enabled = allowEdit

Me.TextBoxAddress4.Enabled = allowEdit

Me.TextBoxTitle1.Enabled = allowEdit

Me.TextBoxTitle2.Enabled = allowEdit

Me.TextBoxTitle3.Enabled = allowEdit

Me.TextBoxEmail.Enabled = allowEdit

Me.ComboBoxPaymentType.Enabled = allowEdit

' Disable any individual controls this users does not have acccess to

Me.ReadWriteAuthorization1.ResetControlAuthorization()

End Sub

RockfordLhotka replied on Thursday, September 18, 2008

I'm not sure I understand the question?

ReadWriteAuthorization is designed specifically to enable/disable controls in a detail form based on whether the user is allowed to read or write to the property bound to each control.

You need to detect when the current principal has changed (as the user logs in and out) because .NET doesn't notify when this happens. And when you detect that change, you need to call the reset method. This concept, and one solution, is discussed in Chapter 9.

Copyright (c) Marimer LLC