SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a DateTimeField control that I would like to only display dates with. I tried setting the DateOnly member to true but when I try to save the page that is using this it throws the following error:

[NullReferenceException: Object reference not set to an instance of an object.]
   Microsoft.SharePoint.WebControls.DateTimeField.set_DateOnly(Boolean value) +30
   ASP.MNCRFPPAGE_ASPX__1578019166.__BuildControlPublishedStartDate() in C:\inetpub\wwwroot\wss\VirtualDirectories\8000\_catalogs\masterpage\MNCRFPPage.aspx:37
   ASP.MNCRFPPAGE_ASPX__1578019166.__BuildControlPageTitleInTitleArea(Control __ctrl) in C:\inetpub\wwwroot\wss\VirtualDirectories\8000\_catalogs\masterpage\MNCRFPPage.aspx:25
   ASP.MNC_MAIN_MASTER__1063580889.__BuildControlPlaceHolderMain() in C:\inetpub\wwwroot\wss\VirtualDirectories\8000\_catalogs\masterpage\MNC_main.master:443
   ASP.MNC_MAIN_MASTER__1063580889.__BuildControlMSO_ContentDiv() in C:\inetpub\wwwroot\wss\VirtualDirectories\8000\_catalogs\masterpage\MNC_main.master:441
   ASP.MNC_MAIN_MASTER__1063580889.__BuildControl__control24() in C:\inetpub\wwwroot\wss\VirtualDirectories\8000\_catalogs\masterpage\MNC_main.master:133
   ASP.MNC_MAIN_MASTER__1063580889.__BuildControl__control2() in C:\inetpub\wwwroot\wss\VirtualDirectories\8000\_catalogs\masterpage\MNC_main.master:16
   ASP.MNC_MAIN_MASTER__1063580889.__BuildControlTree(MNC_MAIN_MASTER__1063580889 __ctrl) in C:\inetpub\wwwroot\wss\VirtualDirectories\8000\_catalogs\masterpage\MNC_main.master:1
   ASP.MNC_MAIN_MASTER__1063580889.FrameworkInitialize() in c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\9a65295e\deeb79d\App_Web_mnc_main.master_-1063580889.y606yxqr.0.cs:0
   System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection) +1304
   System.Web.UI.Page.get_Master() +68
   System.Web.UI.Page.ApplyMasterPage() +17
   System.Web.UI.Page.PerformPreInit() +57
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1255

I found this article which claims that it simply can't be done. Is this correct?

share|improve this question
Came across the same error in SP 2013. Seems the behaviour is same in SP 2013 – Shaamil May 6 '15 at 6:44
up vote 2 down vote accepted

The DateTimeField uses internally a DateTimeControl on which the DateOnly value is set (passed through). But this internal DateTimeControl is not instantiated in the CreateChildControls method of the DateTimeField if the ControlMode of the DateTimeField is SPControlMode.Display.
(I had a look at the source code of the DateTimeField by decompiling it)

So try to avoid setting the DateOnly member of the DateTimeField if the ControlMode of the DateTimeField is equal to SPControlMode.Display.

Please note, that I did not test this solution...

share|improve this answer
Very interesting. So if I want to have a field displayed in both edit and display mode would I have to create two EditModePanels that had the same field in it (one for edit and one for display) and then only set DateOnly on the edit mode panel? – Abe Miessler Jan 31 '12 at 18:39
I don't know your code to confirm your question... Maybe you could also get the current FormMode from SPContext.Current.FormContext.FormMode and set the value for DateOnly if SPContext.Current.FormContext.FormMode != SPControlMode.Display. – Matthias Feb 1 '12 at 9:01

Its kind of old but you can check the solution here.

Basically, DateOnly attribute works fine for newly created layout. But if your layout is already published, you don't need to supply the attribute in designer. Instead:

  • Go to the Site Settings
  • Site libraries and lists (under Site Administration)
  • Customize "Pages"
  • Click the desired DateTimeField name under Columns
  • Modify Date Only.

Hope it helps.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.