none
DateTimeField's DateTime property throwing null reference error

    Question

  • Object reference not set to an instance of an object

    This happens when I try to set DateOnly attribute (=true) of DateTimeField control on a page. Without setting this attribute, the date is displayed without time in view mode BUT the time fields are shown in edit mode.

    Turned out its the drunken-developer-issue at Microsoft (http://sharepoint.stackexchange.com/q/28156/10484)

    Questions:

    • Is there a way to get rid of the time in edit mode as well?
    • Where can we report bugs for Sharepoint? Can't  find MicrosoftConnect for SP, can't find uservoice channel?
    • Whats the ETA on happy-ending of this issue?

    - a citizen of Microsoft Developer Network.

    Monday, September 17, 2012 3:08 PM

Answers

  • McCoy,

    I had the same issue. Consider the following code:

    <SharePointWebControls:DateTimeField
    DateOnly="True"
    id="SomeDate"
    FieldName="72bf294d-16a0-4d75-9746-c88ac9579972"
    runat="server"
    ></SharePointWebControls:DateTimeField>


    This will work ONLY if you did this before publishing your layout! If you already have published the layout and then decided "OH I need to make it DateOnly"... then DO NOT add DateOnly attribute here.

    Go to the Site Settings > Site libraries and lists (under Site Administration) > Customize "Pages"  > Some Date (find and click on your field name under Columns) > turn off Date Only radio button > click Ok > Refresh your edit page > Mark this as an answer :)

    Once after publishing the layout/master-page, SharePoint doesn't auto-apply the changes made columns/fields unless:

    - You ResetIIS OR

    - Use "Site libraries and lists" method to refresh the column attributes (or add the column if you have added the associated field).

    Hopefully Microsoft would realize the agony caused by this shortcoming and fix the issue in SP2013 (and 2010 too via service-pack, if they still care about their developers!)

    • Marked as answer by Real McCoy Tuesday, September 18, 2012 6:10 PM
    Tuesday, September 18, 2012 6:03 PM

All replies

  • i create a new datetime type column and configure it to DateOnly. It works as expected in item edit form.

    BTW, i cannot open the link you pasted. i can seldom open link from this stackexchange site.

    Tuesday, September 18, 2012 9:15 AM
  • Its strange because certain people out there are having this problem

    http://www.entwicklungsgedanken.de/2009/08/21/do-not-use-datetimefield-when-displaying-the-date-of-your-field/

    http://sharepoint.stackexchange.com/questions/28156/possible-to-use-dateonly-with-the-datetimefield-control (unshrinked version of the same URL).

    Expected result: I do not want to see time part with DateTimeField control when its rendered in edit mode.

    Actual result: Throwing error "Object reference not set to an instance of an object".


    - a citizen of Microsoft Developer Network.

    Tuesday, September 18, 2012 3:11 PM
  • McCoy,

    I had the same issue. Consider the following code:

    <SharePointWebControls:DateTimeField
    DateOnly="True"
    id="SomeDate"
    FieldName="72bf294d-16a0-4d75-9746-c88ac9579972"
    runat="server"
    ></SharePointWebControls:DateTimeField>


    This will work ONLY if you did this before publishing your layout! If you already have published the layout and then decided "OH I need to make it DateOnly"... then DO NOT add DateOnly attribute here.

    Go to the Site Settings > Site libraries and lists (under Site Administration) > Customize "Pages"  > Some Date (find and click on your field name under Columns) > turn off Date Only radio button > click Ok > Refresh your edit page > Mark this as an answer :)

    Once after publishing the layout/master-page, SharePoint doesn't auto-apply the changes made columns/fields unless:

    - You ResetIIS OR

    - Use "Site libraries and lists" method to refresh the column attributes (or add the column if you have added the associated field).

    Hopefully Microsoft would realize the agony caused by this shortcoming and fix the issue in SP2013 (and 2010 too via service-pack, if they still care about their developers!)

    • Marked as answer by Real McCoy Tuesday, September 18, 2012 6:10 PM
    Tuesday, September 18, 2012 6:03 PM