Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have implemented the SharePoint:DateTimeControl in a very simple webpart

<SharePoint:DateTimeControl ID="dtStartdate" runat="server" DateOnly="true" />

The problem is when I click on the control it renders an exception

Server Error in '/' Application.
Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 
[NullReferenceException: Object reference not set to an instance of an object.]
   Microsoft.SharePoint.Utilities.SPUtility.GetThemedImageUrl(String originalUrl, String themeKey) +199
   Microsoft.SharePoint.WebControls.DatePicker..ctor() +1460
   Microsoft.SharePoint.WebControls.SPDatePickerControl.InitDatePicker() +44
   Microsoft.SharePoint.WebControls.SPDatePickerControl.set_MinJDay(Int32 value) +25
   Microsoft.SharePoint.ApplicationPages.DatePickerFrame.Page_Load(Object sender, EventArgs e) +1708
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Control.LoadRecursive() +94
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2935

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929

enter image description here

Any advice or help to resolve this is highly appreciated, thanks!

== EDIT ==

Codebehind is as follows

[ToolboxItemAttribute(false)]
public partial class BookingWebPart : WebPart
{
    public BookingWebPart()
    {
    }

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        InitializeControl();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        SPList hotelsList = SPContext.Current.Web.Lists["Hotels"];
        foreach (SPListItem item in hotelsList.Items)
        {
            ddlHotels.Items.Add(new ListItem(item.Title, item.ID.ToString()));
        }
        for (int i = 1; i < 15; i++)
        {
            ddlNumberOfNights.Items.Add(i.ToString());
        }
    }

    protected void btnCreateBooking_Click(object sender, EventArgs e)
    {
        SPList bookingsList = SPContext.Current.Web.Lists["Bookings"];
        SPListItem newItem = bookingsList.Items.Add();
        newItem["Hotel"] = ddlHotels.SelectedValue;
        newItem["Startdate"] = dtStartdate.SelectedDate;
        newItem["Enddate"] = dtStartdate.SelectedDate.AddDays(Convert.ToInt32(ddlNumberOfNights.SelectedValue));
        newItem.Update();
        Page.Response.Redirect(bookingsList.DefaultViewUrl);            
    }
}
share|improve this question
    
Can you show your codebehind? It seems as though you didn't declare your instance of DatePicker. –  Mike Jan 15 '13 at 21:23
    
Added the codebehind –  Eric Herlitz Jan 15 '13 at 21:26
    
Did you solve this problem? I am facing the same issue and cannot figure a way out :( –  user15685 Mar 18 '13 at 16:55
    
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. –  John Chapman Mar 18 '13 at 19:35
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. –  PirateEric Mar 18 '13 at 21:43

2 Answers 2

If you have this Calendar control in a site collection but not under root collection, you may have to create a root site collection.

For example,

www.xxx.com/ (Root site collection not created) www.xxx.com/sites/site1 (Calendar is in this site collection)

share|improve this answer

It seems to be a bug in SharePoint 2013. This is how I solved:

You just need to add the DatePickerFrameUrl attribute to your control declaration

<SharePoint:DateTimeControl ID="dtStartdate" runat="server"
DateOnly="true" DatePickerFrameUrl="<%
$SPUrl:~sitecollection/_layouts/15/iframe.aspx %>" />
share|improve this answer

Your Answer

 
discard

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.