469,964 Members | 1,613 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

Validating Data on User Control and Passing Back to the Page

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.
Nov 19 '05 #1
1 2665
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 CompareValidator with Operator=DataTypeCheck and Type=Date to
determine a correct date and another CompareValidator with
Operator=LessThanEquals 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 TimeOfDayTextBox. 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 TimeOfDayTextBox 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
TimeOfDayTextBox has arrows to advance hours and minutes plus keyboard
filtering.
3. To detect a blank field, just use the RequiredFieldValidator supplied by
Microsoft.
4. To detect an illegal date format, I supply the DateTextBoxValidator. For
an illegal time format, I supply a TimeTextBoxValidator. 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****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"panche" <pa****@nospam.com> wrote in message
news:%2****************@tk2msftngp13.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.

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Al Jones | last post: by
5 posts views Thread by Rod | last post: by
4 posts views Thread by bremdevnet | last post: by
reply views Thread by Gary Shell | last post: by
4 posts views Thread by Tarun Mistry | last post: by
17 posts views Thread by stathis gotsis | last post: by
232 posts views Thread by robert maas, see http://tinyurl.com/uh3t | last post: by
5 posts views Thread by Ludwig | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.