-
ASP.NET Date Validation
Posted on May 6th, 2009 2 commentsA simple requirement at first sight not one with a simple solution.
You have an ASP.NET page which allows the user to specify a date which is then used as an input parameter for an SQL Stored Procedure. What is stopping the user from entering ‘Hello World’ and submitting it?
Answer, nothing unless you configure some sort of validation.
So what sort of validatator do you use? At first sight there does not appear to be a suitable candidate but to enforce a specific format, e.g. dd/mm/yyyy, the RegularExpressionValidator could be called into play here. This will stop the user from entering data in the wrong format but what about invalid date such as 32/12/07 or 29/02/07? How do make sure that the date is a real one?
This is where I was a little while ago and I decided to opt for the CustomValidator, writing my own Server Side and Client Side validation functions that Cast the user input to a DateTime type and catching any exceptions.
While this worked I was not too happy with the operation of the code. Then I watched a PodCast from dnrTV where Peter Blum demonstrated some lesser known features of the ASP.NET validator controls. He used a CompareValidator to check for a valid date – a CompareValidator??!!I normally associate the CompareValidator to check one value against another, e.g. Password and Confirm Password. So how does it validate a date?
- Simply add a CompareValidator and set it’s ControlToValidate to the textbox containing the date.
- Now locate the Operator property and Select DataTypeCheck from the dropdown list.
- Finally set the Type property to Date and you’re done.
So there you have it – no need for custom code on Server or Client side.
This article was originally posted in March 2008 on my [now stagnant] DotNetNoteToSelf blog which will be deactivated in the not too distant future
-
Reading an RSS Feed with C# and Python
Posted on May 5th, 2009 No commentsWhen I started this site I had a project in mind that would download Podcasts as they were posted and maintain the content of my MP3 player so that I didn’t have to do it myself. Well since then I have lost my iTunes virginity and while it doesn’t do everything that I wanted (like telling me that a new episode has been downloaded) it does automatically download and delete them once I’ve watched/listened to them.
But just because I don’t need to develop a complete application there is still an itch to scratch here – a few of them in fact.
- How do I download an RSS stream – it’s not just podcasts that uses them
- How do I parse the resulting XML
- How do I download a file and store it locally
- and how do I do this in C# and Python
Well this post will answer the first two questions using C# and LINQ and Python and it’s XML library.
Read the rest of this entry »


