moopoo.net
Fishing, technology and anything else

Validation Group with SharePoint DateTimeControl

February 16th, 2010 by Matt

The SharePoint DateTimeControl has a property called IsRequiredField, which will act like a RequiredFieldValidator for the control. The problem is when working with web parts in SharePoint calling Page.Validate in your web part can have unexpected results. It often ends up firing validators elsewhere on the page, particularly if the web part is used on a list form for example.
One answer of course is to use a validation group in your web part, this is where the DateTimeControl falls down as it doesn’t have this property.

The answer to this to create a validator in your webpart and hook it into the TextBox element of the DateTimeControl, which will then allow you to set the validation group on it.

To do this use the following code when you create your validator.

valReviewDate.ControlToValidate = string.Format("{0}${0}Date", dteReview.ID);

This post, describes how to do it from code in front.

Posted in SharePoint

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.