Jawad Khan

Jawad's Lodge - The willingness to torture yourself before others is what makes a developer truly a unique breed.
posts - 45, comments - 149, trackbacks - 155

My Links

News

Archives

Post Categories

Image Galleries

Creating Custom XML Placeholder Control ......

MCMS 2002 has a XML placeholder definition object but there is no XML placeholder Web Control shipped with the product. Woodgrove Sample MCMS website comes with a XML placeholder control but it real annoying in the sense that you only have 10 rows of text visible at a time. It is common requirement to customize the XML placeholder feel and look and also the functionality. Here is source for the XML placeholder Control that you can use as it is or customize it according to your needs ....

    Just Add the following class in to your C# class library. After compiling the code you can add this XMLPlaceholder Control by right clicking on your toolbar in Visual Studio design mode and selecting Add/Remove Item. Select the Class library that contains following Class and Control is available just like HtmlPlaceholder ....

using System;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Drawing ;

using System.Xml.XPath ;

using System.Xml.Xsl ;

using System.IO;

using System.ComponentModel ;

using Microsoft.ContentManagement.WebControls ;

using Microsoft.ContentManagement.Publishing.Extensions.Placeholders ;

using McmsWebControlLibrary.PlaceholderControls;

namespace Jawad.Cms.CustomPlaceholders

{

///

/// Summary description for XMLPlaceholderControl.

///

[ToolboxData("<{0}:XMLPlaceholder runat=server>")]

public class XMLPlaceholder : BasePlaceholderControl

{

// Methods

public XMLPlaceholder()

{

this.McmsXmlControlHelper = new McmsXmlControlHelper();

}

protected override void CreateAuthoringChildControls(BaseModeContainer authorContainer)

{

this.tbxXmlContent = new TextBox();

this.tbxXmlContent.Height = (Unit) Unit.Parse (TextBoxHeight);

this.tbxXmlContent.Columns = TextBoxColumns;

this.tbxXmlContent.TextMode = TextBoxMode.MultiLine;

this.tbxXmlContent.Wrap = true;

this.tbxXmlContent.BackColor = Color.LightGray;

authorContainer.Controls.Add(this.tbxXmlContent);

}

protected override void CreatePresentationChildControls(BaseModeContainer presentationContainer)

{

this.lblXmlContent = new Label();

this.lblXmlContent.BackColor = Color.LightGray;

presentationContainer.Controls.Add(this.lblXmlContent);

}

protected override void LoadPlaceholderContentForAuthoring(PlaceholderControlEventArgs e)

{

this.EnsureChildControls();

try

{

XmlPlaceholder placeholder1 = (XmlPlaceholder) base.BoundPlaceholder;

string text1 = placeholder1.XmlAsString;

this.tbxXmlContent.Text = text1;

}

catch (Exception exception1)

{

string text2 = exception1.Message;

}

}

protected override void LoadPlaceholderContentForPresentation(PlaceholderControlEventArgs e)

{

this.EnsureChildControls();

try

{

XmlPlaceholder placeholder1 = (XmlPlaceholder) base.BoundPlaceholder;

string text1 = placeholder1.XmlAsString;

XPathDocument document1 = this.McmsXmlControlHelper.CreateXPathDoc(text1);

string text2 = this.Transform(document1);

this.lblXmlContent.Text = text2;

}

catch (Exception exception1)

{

string text3 = exception1.Message;

}

}

protected override void OnInit(EventArgs e)

{

base.OnInit(e);

}

protected override void OnPopulatingDefaultContent(PlaceholderControlCancelEventArgs e)

{

try

{

this.tbxXmlContent.Text = "Enter XML";

}

catch (Exception exception1)

{

string text2 = exception1.Message;

}

}

protected override void SavePlaceholderContent(PlaceholderControlSaveEventArgs e)

{

try

{

XmlPlaceholder placeholder1 = (XmlPlaceholder) base.BoundPlaceholder;

if (!placeholder1.Equals(null))

{

placeholder1.XmlAsString = this.tbxXmlContent.Text.ToString();

}

}

catch (Exception exception1)

{

string text1 = exception1.Message;

}

}

private string Transform(XPathDocument xmlDoc)

{

string text3;

try

{

string text1 = "";

if (!this.XsltStylesheet.Equals(string.Empty))

{

XslTransform transform1 = new XslTransform();

string text2 = this.Context.Server.MapPath(this.XsltStylesheet);

transform1.Load(text2);

StringWriter writer1 = new StringWriter();

XPathNavigator navigator1 = xmlDoc.CreateNavigator();

transform1.Transform(navigator1, (XsltArgumentList) null, writer1);

text1 = writer1.GetStringBuilder().ToString();

}

text3 = text1;

}

catch (Exception exception1)

{

string text4 = exception1.Message;

text3 = "";

}

return text3;

}

// Properties

[Bindable(true), Browsable(true), Category("Appearance")]

public string XsltStylesheet

{

get

{

string text1 = (string) this.ViewState["XsltStylesheet"];

if (text1 != null)

{

return text1;

}

return string.Empty;

}

set

{

this.ViewState["XsltStylesheet"] = value;

}

}

[Bindable(true), Browsable(true), Category("Appearance")]

public string TextBoxHeight

{

get

{

string text1 = (string) this.ViewState["TextBoxHeight"];

if (text1 != null)

{

return text1;

}

return "400";

}

set

{

this.ViewState["TextBoxHeight"] = value;

}

}

[Bindable(true), Browsable(true), Category("Appearance")]

public int TextBoxColumns

{

get

{

object columns = this.ViewState["TextBoxColumns"];

if (columns != null)

{

return (int)columns;

}

return 150;

}

set

{

this.ViewState["TextBoxColumns"] = value;

}

}

// Fields

private Label lblXmlContent;

private McmsXmlControlHelper McmsXmlControlHelper;

private TextBox tbxXmlContent;

}

}

Print | posted on Monday, May 16, 2005 8:47 PM | Filed Under [ Microsoft Content Management Server ]

Feedback

Gravatar

# re: Creating Custom XML Placeholder Control ......

Well I am new into CMS and your article has helped me a lot.

Thank you very much.
1/12/2006 4:23 AM | Djans
Gravatar

# re: Creating Custom XML Placeholder Control ......

i am new into MCMS. I have add this class in my project but it gives error when compilation of McmswebcontrolLibrary.
Please help me in how to add this class in class library.
2/14/2006 3:05 AM | pallavi
Gravatar

# re: Creating Custom XML Placeholder Control ......

Hello pallavi,
The Reason you are getting the error for McmsWebControlLibrary is because you have too add the reference to anothe DLL that comes as part of the WoodGroove Sample Site for MCMS 2002. I think you can download it free of cost from the Microsoft COntent Management server page download section. Install the sample and copy the dll to any place you want and then add the reference.
Hope that helps
This is the offending statement
using McmsWebControlLibrary.PlaceholderControls
2/15/2006 7:35 AM | Jawad Khan
Gravatar

# re: Creating Custom XML Placeholder Control ......

good day
i follow the instructions

but when i add the XMLPlaceholder to the page i get rectangle error
in the rectangle : error creating control

what is the problem
thank you

7/9/2006 3:20 AM | fadi
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: