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
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);
}
}