Showing posts with label datetimecontrol. Show all posts
Showing posts with label datetimecontrol. Show all posts

July 14, 2008

Styles not rendered when using the SharePoint DateTimeControl in custom pages

When using the SharePoint DateTimeControl in custom pages, the popup calendar is rendered without styles. I don't know why but the problem is that the datepicker.css stylesheet is not referenced as explained on the Rich Finn's blog (http://blog.richfinn.net/2006/12/10/SharePointDateTimeControlDoesNotRenderStyles.aspx).

Have a look on the iframe.aspx page located in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS.

<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages" %> 
<%@ Page Language="C#" Inherits="Microsoft.SharePoint.ApplicationPages.DatePickerFrame"      %> 
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %> 
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Import Namespace="Microsoft.SharePoint" %> 
<% SPSite spServer = SPControl.GetContextSite(Context); SPWeb spWeb = SPControl.GetContextWeb(Context); %>
<html dir="<SharePoint:EncodedLiteral runat='server' text='<%$Resources:wss,multipages_direction_dir_value%>' EncodeMethod='HtmlEncode'/>">
    <HEAD>
    <META Name="GENERATOR" Content="Microsoft SharePoint">
    <SharePoint:CssLink runat="server"/>
    <script src="./DatePicker.js"></script>
    <title>Date Picker</title>
    </HEAD>
    <BODY onload="PositionFrame('DatePickerDiv');" onkeydown="OnKeyDown(this);" style="margin:0;">
      <SharePoint:SPDatePickerControl id="DatePickerWebCustomControl" runat="server" >
          </SharePoint:SPDatePickerControl>
    </BODY>
</HTML>

To solve the problem, you have to add manually the reference to the stylesheet.

<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages" %> 
<%@ Page Language="C#" Inherits="Microsoft.SharePoint.ApplicationPages.DatePickerFrame"      %> 
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %> 
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Import Namespace="Microsoft.SharePoint" %> 
<% SPSite spServer = SPControl.GetContextSite(Context); SPWeb spWeb = SPControl.GetContextWeb(Context); %>
<html dir="<SharePoint:EncodedLiteral runat='server' text='<%$Resources:wss,multipages_direction_dir_value%>' EncodeMethod='HtmlEncode'/>">
    <HEAD>
    <META Name="GENERATOR" Content="Microsoft SharePoint">
    <link rel="stylesheet" type="text/css"href="/_layouts/1033/styles/datepicker.css"/>
    <SharePoint:CssLink runat="server"/>
    <script src="./DatePicker.js"></script>
    <title>Date Picker</title>
    </HEAD>
    <BODY onload="PositionFrame('DatePickerDiv');" onkeydown="OnKeyDown(this);" style="margin:0;">
      <SharePoint:SPDatePickerControl id="DatePickerWebCustomControl" runat="server" >
          </SharePoint:SPDatePickerControl>
    </BODY>
</HTML>