I’m trying to develop an ASP.NET application “by the book”; I have my Web Forms implement MVP pattern, my presenter talks only to Services layer that than talks to a bunch of repositories all sharing my own EF ObjectContext. So far so good. Now I’m tackling the front end and I have a dilemma…
Lets say I have an asp:TextBox control named txtDateOfBirth and submit button. When a user clicks the button, I need to send data from ASPX to presenter to Service to …. but the problem is that in the end I don’t need String, but DateTime? and I don’t know the best place to make the conversion:
- Should I put a validator in ASPX page and then in code-behind do the conversion?
- Or should I collect a bunch of strings from the form, create a request for the service containing only strings, and than have my Business Model do the try/convert and report errors?
What do you recommend? Any insight is appreciated…
EDIT: OK, after having read and tried all of your suggestions, I decided to go with the following:
- Code-behind and APSX are responsible for data type conversions. I
decided to go with simple CompareValidator and check for the
appropriate type so code-behind can surely convert it. - Request that goes from presenter to service layer is appropriately
typed. - All other validation is being done by business layer (including
string lengths, required or not, range, …)
If I understood that correctly, you have an textbox in your WebForm where the user writes something that should be a date, right?
There are somethings you can do: