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>

1 comment:

Anonymous said...

Hi,
I also use DateTimeControl inside a webpart. It displays ok, but whenever i click on the calendar image, the page generate the below error. I followed the example from the site http://www.sharepoint-tips.com/2007/10/using-sharepoint-date-control-in-web.html ; it shouldn't be too hard....

Exception message: Could not load file or assembly 'Microsoft.SharePoint.ApplicationPages' or one of its dependencies.
The system cannot find the file specified.

Request information:



Stack trace: at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)
at System.Web.UI.TemplateParser.ParseFile(String physicalPath, VirtualPath virtualPath)
at System.Web.UI.TemplateParser.ParseInternal()
at System.Web.UI.TemplateParser.Parse()
at System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType()
at System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider)
at System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()
at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
at System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)