Mombu the Microsoft Forum sponsored links

Go Back   Mombu the Microsoft Forum > Microsoft > Set a customized placeholder control
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 6th July 19:18
manu
External User
 
Posts: 1
Default Set a customized placeholder control



Hi everrybody,

I'm trying to set the value by C# code of a customized
placeholder control that contains a dropdown list in
authoring mode and a label in published mode.

Can I Access at the Text property of the label inside the
customized placeholder control in any way?

This is the portion of code that I'm using:
string sInnerTextNode = XmlNode.InnerText.ToString();
Posting po = channel.CreatePosting(template);
po.Placeholders[sNomPhNode]. ...<write the Text property
of the label> ... = sInnerTextNode;

Thx a lot
  Reply With Quote


  sponsored links


2 6th July 19:18
stefan [msft]
External User
 
Posts: 1
Default Set a customized placeholder control



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;
}
}

}
}
  Reply With Quote
3 13th July 13:08
manu
External User
 
Posts: 1
Default Set a customized placeholder control


Thanks a lot Stefan! It Works! ;-)

Regards,
Manu

control.

placeholder to the


following code:

[sNomPhNode])


[sNomPhNode])

an "as is" basis


limitation warranties


entire risk as to

Microsoft.ContentManagement.Publishing.Extensions. Placehold
ers;


(HtmlPlaceholderDefinition)),


(System.Web.UI.Design.WebControls.ListItemsCollect ionEditor
),


(System.Web.UI.Design.WebControls.ListItemsCollect ionEditor
),


(DesignerSerializationVisibility.Hidden),


(DesignerSerializationVisibility.Hidden),


(BaseModeContainer

(_AllowedValues[i].Text);

this.ddlAuthoringControl );

list item


(PlaceholderControlEventArgs e)

this.BoundPlaceholder).Html;


(valueOfListItem);

collection

(BaseModeContainer


= "LitPresentationControlControl";

this.litPresentationControl );

literal text


(PlaceholderControlEventArgs e)


= "Hello World!";


\"{1}\"] Error saving

exp.Message);

(newExceptionMessage, exp);
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666