views:

95

answers:

1

I've skinned this cat a few different ways over the last 6 years.. hardcoded strings, static classes with consts, and resource files. What approach do you use, and why? Bonus points for integrating with client-side error messages!

+1  A: 

i use a business-object layer that includes a validation method

public bool ValidateData(IList<string> errs)

the error messages are added to the collection as strings formatted from program constant templates (globalization is not a concern obviously), e.g. "{0} cannot be empty, please enter a value for the {0}" where {0} is the field name

the same business layer works for web and desktop apps

EDIT: the error message collection is passed back to the winform in an error-message lable, or to the webform in an error-message label. (no javascript is required)

i have also used a variant of this that takes an IDictionary where the first string is the field name and the second string is the error message, and a helper function finds the form element bound to the named field for highlighting

in general, i use approximately the same pattern in most application systems, depending on the customer needs

Steven A. Lowe
Hmm, so you hard code your error messages as consts. Do you pass these string lists down to JavaScript so that you have consistent error messages on the client?
EvilSyn
@EvilSyn: see edits
Steven A. Lowe