Hi Panache,
Start with learning about the Validator web controls supplied with ASP.NET.
They handle many of these tasks and let you extend them using the
CustomValidator webcontrol to provide additional logic. They are documented
in the .net docs.
Now for the challenges. You say you have two textboxes two hold 4 pieces of
data: start date, start time, end date, and end time. I'm guessing that
means you demand the user to enter a date + space + time into each text box.
That makes things harder on you and the user.
- For you, you cannot use the built in validators to handle dates. Normally
you use the CompareValidato r with Operator=DataTy peCheck and Type=Date to
determine a correct date and another CompareValidato r with
Operator=LessTh anEquals and Type=Date to compare two date textboxes. Since
you have a time in there, these are not available.
- For your user, they have to learn your syntax of date+space+time . Having
two separate fields not only limits them to entering a single format into
each textbox but also lets you add a popup calendar to the DateTextBox and
other supporting tools to the TimeOfDayTextBo x. For example, keyboard
filtering to omit illegal characters.
I speak from experience as I am the author of one of the most popular web
controls for Date and Time entry, in Peter's Date Package
(
http://www.peterblum.com/datecontrols/home.aspx). I encourage you to take a
look at what I've built (its very inexpensive) and see if it helps. Here's
how it answers your questions:
1. There is a separate DateTextBox and TimeOfDayTextBo x that can be
interconnected so your server side code only deals with a single DateTime
value.
2. The DateTextBox has a popup calendar and keyboard filtering. The
TimeOfDayTextBo x has arrows to advance hours and minutes plus keyboard
filtering.
3. To detect a blank field, just use the RequiredFieldVa lidator supplied by
Microsoft.
4. To detect an illegal date format, I supply the DateTextBoxVali dator. For
an illegal time format, I supply a TimeTextBoxVali dator. In addition, these
validators recognize when the two controls are connected and complain if
both are not filled in.
5. I supply a compare validator for From Date+Time and To Date+Time.
6. I supply a difference validator to be sure the number of days between the
dates is not exceeded.
--- Peter Blum
www.PeterBlum.com
Email:
PL****@PeterBlu m.com
Creator of "Profession al Validation And More" at
http://www.peterblum.com/vam/home.aspx
"panche" <pa****@nospam. com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I'm developing a fairly simple user control that has two textboxes for
date/time entry (a from date/time and a to date/time). One of my
requirements is that there should be no button that sets these values
(i.e.,
no button to cause a postback). The problem I'm having is that I need a
number of validations to be performed on the data entry, but I don't know
how to do this without having the user control/page posted back to the
server. Basically, I need some way to dynamically validate the user input
without a postback to the server.
The validations that I need are:
** Is the text entered a valid date/time string?
** Is there some value (i.e., cannot be null/empty)?
** The to date/time cannot be before the from date/time
** The time span cannot be greater than 1 year.
Can some one please help me identify ways to do this type of validations
of
user input without a postback to the server?
Also, once the data is entered and in the correct format, how do I get
those
values off the .ascx and into the page itself, also without a postback?
Therefore, as the user enters data, the data needs to be dynamically
validated and given to the page (and/or put into session state) so that I
can use it later after the user goes on to the next page.
Hope all this makes sense. Any help is greatly appreciated.