次の方法で共有


Optional content/fields in SharePoint - quick solution

I had a discussion with a CMS/SharePoint consultant, Eric Fontaine, and he was asking me about having "Optional content" or fields in a MOSS environment; basically, the idea was to have a content section appear depending on the author.  There was something similar to that effect in CMS .

 

Unfortunately, this isn't out of the box with SharePoint, however, the solution was quite simple : we created a simple control in C# that inherits from the ASP.NET Panel and added a property that makes its visible state modify depending on a SharePoint column value.  This little solution helped us much more than originally thought and we can't live without it now!  There are 3 variants of it now :

  1. Visible = PageContent.AnyTextOrHtmlField.Value.Length > 0 : this is great for a small panel where, if an Html or Text field is empty, it becomes invisible.  The author doesn't implicitly choose the visibility with a checkbox.
  2. Visible = PageContent.CheckboxField.Value : this is great to have a panel containing a few controls & text to disappear or that you need the author to choose.
  3. Template1.Visible = CheckBox.Value; Template2.Visible = !CheckBox.Value:  this is great when you have 2 templates depending on the author's choice.  In our case, we had a picture to show in gray when the checkbox was not selected;  and in color when the checkbox was selected by the author.

 

1. Optional content based on a checkbox

<MyControl:ConditionalCheckPanel runat="server" ControlToValidate="Checkbox1" EnableViewState="false">

<h3>My Title</h3>

<PublishingWebControls:RichHtmlField InputFieldLabel="my field label" FieldName="HtmlField1" runat="server" ID="HtmlField1" />

<PublishingWebControls:RichHtmlField InputFieldLabel="my field label2" FieldName="HtmlField2" runat="server" ID="HtmlField2" />

</MyControl:ConditionalCheckPanel>

 

2. Optional content based on a control's value length

<MyControl:ConditionalFieldPanel runat="server" ControlToValidate="HtmlField1" EnableViewState="false">

<h3>My Title</h3>

<PublishingWebControls:RichHtmlField InputFieldLabel="my field label" FieldName="HtmlField1" runat="server" ID="HtmlField1" />

</MyControl:ConditionalFieldPanel>

 

3. "Choice" content based on Checkbox with 2 templates

<MyControl:ConditionalPanel Column="Checkbox1" runat="server" EnableViewState="false">

<TemplateChecked>

<img src="on.gif" alt="On">

</TemplateChecked>

<TemplateUnchecked>

<img src="off.gif" alt="Off">

</TemplateUnchecked>

</MyControl:ConditionalPanel>

 

All in all, very small controls to develop (only a few development minutes) but very very handy.

 

Maxime

Comments