I have a .NET 2.0, application with several types of Controls (Check boxes, Buttons, etc), that I need to Enable or Disable them according the kind of License that the user bought. I wonder if there is a way to support this as an Aspect, like using Injection or a Proxy that can intercept the call to Enable or other Properties of the Control, and the desired logic can be added there. If it matters, I use Infragistics controls. Any othe开发者_开发技巧r thoughts about this issue? Other approachs/patterns? Thanks
You could make a custom attribute to decorate the controls with, and then recursively loop over all your controls and check for that attribute to set the desired state.
is it not possible to do it inside the Form_Load() event?
if(LicenseType.SomeCheckBoxDisabled) {
Form1.SomeCheckBox.Enabled = false;
}
Add an additional attribute to every control you want to protect. Something like...
<asp:Button ID="Button1" runat="server" RequiredLicense="PremiumEdition">Click here</asp:Button>
If I recall correctly, ASP.NET allows you to add undefined attributes to controls, which will be available in the control's Attributes property.
Then, in your BasePage class' initialization (i.e. PreRender, PageLoad, etc.) you could recursively loop through the page's controls and look for controls having the "RequiredLicense" attribute and hide or disable as needed.
Thanks for all the answers. I think that my question was not clear since I was not sure what I was looking for. The answer for what I was looking for: My application is written used the CAB framework. In order to Enable/disable controls in the application according to the sold package I will use the Command Pattern as implemented in the SCFS. Thanks
精彩评论