Geeks With Blogs

Tangible Thoughts SharePoint, MOSS? and all the other questions

As a developer wanting to create a WebPart that needs a date picker everybody will tempted to use SharePoint's date picker.

Unless you know how to use it you are going to run into a couple of gotchas.

Basically everybody initially stumbles, trying to find a way to get it to display.

What you should ideally do to use the OWSDateField is

OWSForm frm1 = new OWSForm();

OWSDateField df1 = new OWSDateField();

frm1.Controls.Add(df1);

If you are creating an ASP.NET form, you would need to have the following script includes on your page.

<SCRIPT src="/_layouts/1033/owsbrows.js"></SCRIPT>

<SCRIPT language="javascript" src="/_layouts/1033/ows.js"></SCRIPT>

The next catch is any control event hander will not work. For instance button/link button click’s will no longer generate a postback. This is because the OWSForm is basically some ‘special’ JavaScript that is added to the page. What you need to do is, in addition add an OWSSubmitButton to the OWSForm. But the OWSSubmitButton does not have an event handler; it just generates a postback when it’s clicked, basically through a javascript function that’s added to the page courtesy of the Submit button. You will have to work something out here to get the event handlers of your controls to work. I basically use a scheme based on checking if a control has been clicked processing it on Page Load if Page.IsPostback.

But even once you finally got it to display on your form/WebPart still you run into trouble. Basically you feel this should work but it doesn’t; until you really know how to use it; i.e. to assign an initial date to the OWSDateField you need to assign it with the time component.

i.e. you need to assign the initial value of the OwsDateField as yyyy-MM-ddThh:mm:ssZ

Hope this helps. Thanks goes to Suranja for pointing out some of these to me.

Posted on Friday, December 17, 2004 11:26 AM Misc | Back to top


Comments on this post: Using the OWSDateField

# re: Using the OWSDateField
Requesting Gravatar...
Useful WScontrol Article in this respect :

http://www.codeproject.com/aspnet/SharePointFormControls.asp
Left by BoringCoder on Apr 21, 2006 10:21 AM

# re: Using the OWSDateField
Requesting Gravatar...
hey, this is a cool date picker control:
http://baigadil.blogspot.com/2008/07/date-picker-control-for-sharepoints.html
Left by Mark on Jul 19, 2008 4:29 AM

Your comment:
 (will show your gravatar)


Copyright © Tariq | Powered by: GeeksWithBlogs.net