<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Coeamyd's - SharePoint</title>
    <link>http://www.coeamyd.net/</link>
    <description>...It ain't easy being green</description>
    <language>en-us</language>
    <copyright>Christoph Herold</copyright>
    <lastBuildDate>Wed, 19 Nov 2008 16:37:25 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.9.6264.0</generator>
    <managingEditor>Christoph.Herold@coeamyd.net</managingEditor>
    <webMaster>Christoph.Herold@coeamyd.net</webMaster>
    <item>
      <trackback:ping>http://www.coeamyd.net/Trackback.aspx?guid=561b2b93-bfa5-4ad7-9805-d939b2b9301e</trackback:ping>
      <pingback:server>http://www.coeamyd.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.coeamyd.net/PermaLink,guid,561b2b93-bfa5-4ad7-9805-d939b2b9301e.aspx</pingback:target>
      <dc:creator>Christoph Herold</dc:creator>
      <wfw:comment>http://www.coeamyd.net/CommentView,guid,561b2b93-bfa5-4ad7-9805-d939b2b9301e.aspx</wfw:comment>
      <wfw:commentRss>http://www.coeamyd.net/SyndicationService.asmx/GetEntryCommentsRss?guid=561b2b93-bfa5-4ad7-9805-d939b2b9301e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today, I was building a nice little page layout for SharePoint and wanted to use SharePoint
DateTimeField control. Since the field I wanted to edit was DateOnly, I set the corresponding
property, leaving me with this code:
</p>
        <p>
          <span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">&lt;SharePointWebControls:DateTimeField
runat=<span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px;">"server"</span> id=<span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px;">"dtfArticleStartDate"</span> DateOnly=<span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px;">"true"</span> FieldName=<span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px;">"ArticleStartDate"</span> /&gt;</span>
        </p>
        <p>
Seems fine to me, but ASP.NET did not like it. Or rather, the control did not like
it. I got an ArgumentException with the following StackTrace:
</p>
        <p>
 
</p>
        <p>
          <span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">[ArgumentException:
FieldName value is not specified.]<br />
Microsoft.SharePoint.WebControls.FieldMetadata.get_Field() +150<br />
Microsoft.SharePoint.WebControls.DateTimeField.CreateChildControls() +310<br />
System.Web.UI.Control.EnsureChildControls() +87<br />
Microsoft.SharePoint.WebControls.DateTimeField.set_DateOnly(Boolean value) +29<br />
ASP.MYNEWSPAGE_ASPX__2072755151.__BuildControldtfArticleStartDate()</span>
        </p>
        <p>
FieldName value is not specified?! As you can see in my code above, it is indeed specified.
But the stack trace gives us more information: The exception occurs in the compiled
ASPX file.
</p>
        <ul>
          <li>
ASP.MYNEWSPAGE_ASPX__2072755151.__BuildControldtfArticleStartDate():<br />
- We are building my DateTimeField control.</li>
          <li>
DateTimeField.set_DateOnly:<br />
- We are setting the DateOnly property.</li>
          <li>
FieldMetadata.get_Field:<br />
- Getting the field is where the exception occurs.</li>
        </ul>
        <p>
Note my ASPX-code again: I first set DateOnly="true" and then FieldName="ArticleStartDate".
Oh my god, this can't be true... The solution is very simple: change the order of
the attributes/properties:
</p>
        <p>
          <span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">&lt;SharePointWebControls:DateTimeField
runat=<span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px;">"server"</span> id=<span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px;">"dtfArticleStartDate"</span><span style="color: #cc0000; background-color: #ffcccc; font-family: Courier New; font-size: 11px;">FieldName="ArticleStartDate"
DateOnly="true"</span> /&gt;</span>
        </p>
        <p>
Against all good practices, the SharePoint team actually created a direct dependency
between two properties. At least the stack trace directly tells you where things go
wrong, so the solution is obvious. Nonetheless, I thought, this was worth noting.
It actually made me laugh, when I encountered it. Another one of those nice little
pitfalls when working with SharePoint :-)
</p>
        <img width="0" height="0" src="http://www.coeamyd.net/aggbug.ashx?id=561b2b93-bfa5-4ad7-9805-d939b2b9301e" />
      </body>
      <title>SharePoint DateTimeField control and the order of its properties</title>
      <guid isPermaLink="false">http://www.coeamyd.net/PermaLink,guid,561b2b93-bfa5-4ad7-9805-d939b2b9301e.aspx</guid>
      <link>http://www.coeamyd.net/PermaLink,guid,561b2b93-bfa5-4ad7-9805-d939b2b9301e.aspx</link>
      <pubDate>Wed, 19 Nov 2008 16:37:25 GMT</pubDate>
      <description>&lt;p&gt;
Today, I was building a nice little page layout for SharePoint and wanted to use SharePoint
DateTimeField control. Since the field I wanted to edit was DateOnly, I set the corresponding
property, leaving me with this code:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;lt;SharePointWebControls:DateTimeField
runat=&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; id=&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px;"&gt;"dtfArticleStartDate"&lt;/span&gt; DateOnly=&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px;"&gt;"true"&lt;/span&gt; FieldName=&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px;"&gt;"ArticleStartDate"&lt;/span&gt; /&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Seems fine to me, but ASP.NET did not like it. Or rather, the control did not like
it. I got an ArgumentException with the following StackTrace:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;[ArgumentException:
FieldName value is not specified.]&lt;br /&gt;
Microsoft.SharePoint.WebControls.FieldMetadata.get_Field() +150&lt;br /&gt;
Microsoft.SharePoint.WebControls.DateTimeField.CreateChildControls() +310&lt;br /&gt;
System.Web.UI.Control.EnsureChildControls() +87&lt;br /&gt;
Microsoft.SharePoint.WebControls.DateTimeField.set_DateOnly(Boolean value) +29&lt;br /&gt;
ASP.MYNEWSPAGE_ASPX__2072755151.__BuildControldtfArticleStartDate()&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
FieldName value is not specified?! As you can see in my code above, it is indeed specified.
But the stack trace gives us more information: The exception occurs in the compiled
ASPX file.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
ASP.MYNEWSPAGE_ASPX__2072755151.__BuildControldtfArticleStartDate():&lt;br /&gt;
- We are building my DateTimeField control.&lt;/li&gt;
&lt;li&gt;
DateTimeField.set_DateOnly:&lt;br /&gt;
- We are setting the DateOnly property.&lt;/li&gt;
&lt;li&gt;
FieldMetadata.get_Field:&lt;br /&gt;
- Getting the field is where the exception occurs.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Note my ASPX-code again: I first set DateOnly="true" and then FieldName="ArticleStartDate".
Oh my god, this can't be true... The solution is very simple: change the order of
the attributes/properties:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;lt;SharePointWebControls:DateTimeField
runat=&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; id=&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px;"&gt;"dtfArticleStartDate"&lt;/span&gt; &lt;span style="color: #cc0000; background-color: #ffcccc; font-family: Courier New; font-size: 11px;"&gt;FieldName="ArticleStartDate"
DateOnly="true"&lt;/span&gt; /&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Against all good practices, the SharePoint team actually created a direct dependency
between two properties. At least the stack trace directly tells you where things go
wrong, so the solution is obvious. Nonetheless, I thought, this was worth noting.
It actually made me laugh, when I encountered it. Another one of those nice little
pitfalls when working with SharePoint :-)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.coeamyd.net/aggbug.ashx?id=561b2b93-bfa5-4ad7-9805-d939b2b9301e" /&gt;</description>
      <comments>http://www.coeamyd.net/CommentView,guid,561b2b93-bfa5-4ad7-9805-d939b2b9301e.aspx</comments>
      <category>.NET;ASP.NET;Development;Pitfall;SharePoint</category>
    </item>
  </channel>
</rss>