How do I extend the RangeValidator control to handle custom dates?

G

Guest

Looking through WebUIValidation.js, I discovered that the standard validators
don't cater for non-numeric date formats (e.g. dd-MMM-yyyy) which I would
like to do

To keep code to a minimum, I would like to extend the existing validator to
handle other common date formats and still be able to do both client and/or
server side validation as normal. Unfortunately, I am unable to get the
extended code to ever be called

I implemented the EvaluateIsValid method and registering a client script
within OnPreRender but this code never seems to run at all. I also tried
temporarily hacking ever instance of the WebUIValidation.js code on my
computer for my current version of ASP.NET without any change either

Ideas on debugging, extension or deployment in this scenario appreciated
 
B

bruce barker

to fire the EvaluateIsValid method, call Page.IsValid property.

-- bruce (sqlwork.com)

| Looking through WebUIValidation.js, I discovered that the standard
validators
| don't cater for non-numeric date formats (e.g. dd-MMM-yyyy) which I would
| like to do
|
| To keep code to a minimum, I would like to extend the existing validator
to
| handle other common date formats and still be able to do both client
and/or
| server side validation as normal. Unfortunately, I am unable to get the
| extended code to ever be called
|
| I implemented the EvaluateIsValid method and registering a client script
| within OnPreRender but this code never seems to run at all. I also tried
| temporarily hacking ever instance of the WebUIValidation.js code on my
| computer for my current version of ASP.NET without any change either
|
| Ideas on debugging, extension or deployment in this scenario appreciated
|
 
G

Guest

Thanks

I can try that. Why do I need to do an explicit Page.IsValid when using the
extended control whereas the standard validation fires automatically without
me having to do anything like that?
 
P

Peter Blum

Simply put, the Microsoft CompareValidator is limited to short date pattern.
No month names, just digits. Don't bother modifying their client-side code.
The ramifications are big. For example, validators also validate on the
server side. So you have to enhance the server side validator too.

Here are two solutions:
1. Use a CustomValidator where you write both the client and server side
evaluation functions.
2. Use Peter's Date Package
(http://www.peterblum.com/datecontrols/home.aspx). It provides a DateTextBox
with popup calendar. You have the option of using abbreviated date entry:
MMM. It includes a number of validators which support the abbreviated date
entry. The validators include full client-side support.
When you install the free trial version, add a DateTextBox to the page. Then
set the AllowMonthNames property to "Show"; this will give you abbreviated
month entry.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
G

Guest

Thanks

It is because the standard validators work both client and server side that
I thought the most elegant solution is to extend the existing functionality
and reduce the need for custom code

I am aware there are alternatives to the approach I would like to take, but
I am interested in why extending the standard validators is not viable and
why to date I am having difficulty making this approach work
 
P

Peter Blum

Hi JK,

Perhaps you didn't know, but I am the author of the leading replacement to
the Microsoft validators (Professional Validation And More).
I had written a number of Microsoft style validators (including those I
mentioned in Peter's Date Package) and kept coming up against its
limitations. Many are due to their design, which is really pretty poor at
extendability. You can find a detailed analysis of these limitations at
http://www.peterblum.com/vam/valmain.aspx.

In this case, the Type property is connected to several internal systems on
the server side. The property itself is an enumerated type, so its not
extendable. You cannot create a new "Date with abbrev month" type in the
property. Both the RangeValidator and CompareValidator use the Type property
to run code that converts strings and compares them. So they are subclassed
from System.Web.UI.WebControls.BaseCompareValidator. BaseCompareValidator
offers two methods to handle the Type property values. Unfortunately, they
are static/shared, not overrideable. So you cannot expand this system.

In Professional Validation And More, I defined data types as unique objects.
The Type property is expandable. The user can create new data types,
following documentation I provide in a free Developer's Kit.

Just to avoid confusion, Peter's Date Package offers validators for its
DateTextBox. Professional Validation And More also offers DataType=Date on
its validators, but its own format is limited to the shortDatePattern. Users
who have both products will see that Peter's Date Package extends the list
of data types offered on all validators so they can have the extended date
format that includes the abbreviated months. For this particular issue,
Peter's Date Package will solve the problem.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
G

Guest

Thanks

FYI: we are already pursuing options to purchase both packages

I do not wish to change the data type, just the behaviour of the
client/server validation routines. This looks like a dead end unless someone
has successfully subclassed the rangevalidator or comparevalidator and can
show me where I'm going wrong
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top