views:

127

answers:

2

Hello.

My typical application has a couple of textboxes, checkbuttons, radiobuttons, and so. I always want to load the settings the user used the last time when the program starts, and also want to save the settings as the users clicks "Save settings" or closes the application. When the user attempts to save the settings, I'll have to check each of the controls for input errors (sometimes they have to have a max length, other times only caps, other times other things, there isn't a rule for them all, everytime it'll be different), and only if everything's OK i'll let him save the options. If there is something wrong, no option is saved and my errorcontrol provider will pop up a description of the input type info that should be put in that control.

I've been designing this from scratch for all my projects, but it's being a pain to do it. So I'd thought maybe now was the time to do some library to help me. I thought initially that maybe it'd be a good idea to have all the controls on my form that are going to be part of this save/load process to have an attribute associated with them, something like this

public delegate bool InputIsOkHandler();

public class OptionsAttribute : Attribute {

public Control controlRef;
public InputIsOkHandler IsInputOk;
public string errorMessageToShowOnErrorProvider;

    public OptionsAttribute(Control controlRef, InputIsOkHandler inputHandler, string errMessage) {
...
}
}

The main problem here is that when I declare the attribute on a given var:

[Options(...)]
TextBox textBox1 = new TextBox();

I'll get

Error 1 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type.

So I guess this approach isn't the best one. What would you guys do in this situation? Would you use attributes? Would you use other mechanisms?

Thanks

+1  A: 

Do you know that .NET already includes such a system since 2.0? See MSDN, CodeProject and this white paper from WestWind.

Alexey Romanov
I'll read it now.
devoured elysium
From what I've read on codeproject, that is just what I was looking for. Thannks!
devoured elysium
A: 

The Personalization and User Profiles supported in ASP.NET 2.0 can be a nice way to achieve your goal. You can check this MSDN article for a overview Personalization in ASP.NET 2.0

Pradeepneo