SharePoint Dragons

Nikander & Margriet on SharePoint

Gotcha for validating the textfield of the SharePoint DateTime control

If you’re planning to use the SharePoint date time control. a good place to start is the followiing: http://karinebosch.wordpress.com/sharepoint-controls/datetimecontrol-control/ It won’t tell you how to use validation controls in combination with it, and there’s an important gotcha involved. If you want to access the textfield rendered by the SharePoint date time control, you need to set the ControlToValidate property to the name of the control in the following format: [control id]$[control id]Date, for example: MyControl$MyControlDate, like so:

<SharePoint:DateTimeControl runat=”server” ID=”MyControl” DateOnly=”true” ShowWeekNumber=”true” LocaleId=”1043″ IsRequiredField=”true” />
<SharePoint:InputFormCustomValidator runat=”server” ID=”MyCustomValidator” ControlToValidate=”MyControl$MyControlDate”
Display=”Dynamic” SetFocusOnError=”true” OnServerValidate=”ValidateFromDateControl” />

Also see: http://www.greggalipeau.com/2008/06/27/sharepoint-datetimecontrol-validation/

2 responses to “Gotcha for validating the textfield of the SharePoint DateTime control

  1. Eirik Johannessen October 16, 2014 at 9:22 am

    Is it only me or is this even worse in SharePoint 2013 ? I get ctl00$PlaceHolderMain$FieldName$ctl00$DateTimeField$DateTimeFieldDate

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: