Hi Manu,
below is a working sample of a drop down placeholder control.
To write content to a placeholder you need to cast the placeholder to the
correct type.
So if you are using an XmlPlaceholder you should use the following code:
Posting po = channel.CreatePosting(template);
XmlPlaceholder xmlph = (XmlPlaceholder)(po.Placeholders[sNomPhNode])
xmlph.XmlAsString = sInnerTextNode;
If it is an HtmlPlaceholder:
Posting po = channel.CreatePosting(template);
HtmlPlaceholder htmlph = (HtmlPlaceholder)(po.Placeholders[sNomPhNode])
htmlph.html = sInnerTextNode;
Cheers,
Stefan.
///
/// This source code is freeware and is provided on an "as is" basis
without warranties of any kind,
/// whether express or implied, including without limitation warranties
that the code is free of defect,
/// fit for a particular purpose or non-infringing. The entire risk as to
the quality and performance of
/// the code is with the end user.
///
using System;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Text.RegularExpressions;
using System.Web.UI.Design.WebControls;
using Microsoft.ContentManagement.Publishing;
using Microsoft.ContentManagement.Publishing.Extensions. Placeholders;
using Microsoft.ContentManagement.WebControls.Design;
using Microsoft.ContentManagement.WebControls;
namespace DropDownPlaceholderControl
{
/// <summary>
/// Summary description for DDPhCtrl.
/// </summary>
[
ToolboxData("<{0}

ropDownPhControl
runat=server></{0}

ropDownPhControl>"),
SupportedPlaceholderDefinitionType(typeof(HtmlPlac eholderDefinition)),
ParseChildren(true, "AllowedValues"),
]
public class DropDownPhControl : BasePlaceholderControl
{
private DropDownList ddlAuthoringControl;
private Literal litPresentationControl;
private ListItemCollection _AllowedValues;
// [
// Browsable(true),
// Description("DropDown Selection"),
// Category("DropDown"),
//
Editor(typeof(System.Web.UI.Design.WebControls.Lis tItemsCollectionEditor),
typeof(UITypeEditor)),
// ]
// public ListItemCollection AllowedValues
// {
// get{return _AllowedValues ;}
// set{_AllowedValues = value;}
// }
[
Browsable(true),
Description("DropDown Selection"),
DefaultValue(null),
Category("DropDown"),
MergableProperty(false),
PersistenceMode(PersistenceMode.InnerDefaultProper ty),
Editor(typeof(System.Web.UI.Design.WebControls.Lis tItemsCollectionEditor),
typeof(UITypeEditor)),
]
public virtual ListItemCollection AllowedValues
{
get
{
if (_AllowedValues == null)
{
_AllowedValues = new ListItemCollection();
}
return _AllowedValues;
}
}
[
Bindable(false),
Browsable(false),
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Hidden),
EditorBrowsableAttribute(EditorBrowsableState.Neve r)
]
public override Unit Height
{
get{ return base.Height; }
set{}
}
[
Bindable(false),
Browsable(false),
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Hidden),
EditorBrowsableAttribute(EditorBrowsableState.Neve r)
]
public override Unit Width
{
get{ return base.Width; }
set{}
}
public DropDownPhControl()
{
//
// TODO: Add constructor logic here
//
}
protected override void CreateAuthoringChildControls(BaseModeContainer
authoringContainer)
{
this.ddlAuthoringControl = new DropDownList();
this.ddlAuthoringControl.ID = "DDLAuthoringControl";
this.ddlAuthoringControl.EnableViewState = false;
for (int i=0; i<_AllowedValues.Count; i++)
this.ddlAuthoringControl.Items.Add(_AllowedValues[i].Text);
authoringContainer.Controls.Add( this.ddlAuthoringControl );
}
// load content into the authoring control by selecting list item
protected override void
LoadPlaceholderContentForAuthoring(PlaceholderCont rolEventArgs e)
{
EnsureChildControls();
try
{
string valueOfListItem = ((HtmlPlaceholder)this.BoundPlaceholder).Html;
ListItem selectedListItem =
this.ddlAuthoringControl.Items.FindByText(valueOfL istItem);
this.ddlAuthoringControl.SelectedIndex =
this.ddlAuthoringControl.Items.IndexOf(selectedLis tItem);
}
catch (Exception) {}
}
// define and add the presentation control to the collection
protected override void CreatePresentationChildControls(BaseModeContainer
presentationContainer)
{
this.litPresentationControl = new Literal();
this.litPresentationControl.ID = "LitPresentationControlControl";
presentationContainer.Controls.Add( this.litPresentationControl );
}
// load content into the presentation control as literal text
protected override void
LoadPlaceholderContentForPresentation(PlaceholderC ontrolEventArgs e)
{
try
{
this.litPresentationControl.Text =
((HtmlPlaceholder)this.BoundPlaceholder).Html;
}
catch (Exception exp)
{
this.litPresentationControl.Text = exp.Message;
}
}
// save the selected item from the drop-down list as XML
protected override void
SavePlaceholderContent(PlaceholderControlSaveEvent Args e)
{
EnsureChildControls();
try
{
((HtmlPlaceholder)this.BoundPlaceholder).Html = "Hello World!";
((HtmlPlaceholder)this.BoundPlaceholder).Html =
this.ddlAuthoringControl.SelectedItem.Text;
}
catch (Exception exp)
{
string newExceptionMessage = String.Format( "[{0} \"{1}\"] Error saving
placeholder content: {2}", this.GetType().Name, this.ID, exp.Message);
Exception overriddenException = new Exception(newExceptionMessage, exp);
throw overriddenException;
}
}
}
}