Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I'm trying to create a custom placeholder control for MS Content Management Server 2002. I encounter an error as below:

 

 

Save Placeholder Failed

----------------------------------------------------------

Error Details:

The data at the root level is invalid. Line 1, position 1.

 

 

 

The custom placeholder implementation is as below:

 

Imports System.Xml
Imports System.Xml.Xsl
Imports System.Web.UI.WebControls
Imports Microsoft.ContentManagement.Publishing
Imports Microsoft.ContentManagement.Publishing.Extensions.Placeholders
Imports Microsoft.ContentManagement.WebControls.Design
Imports Microsoft.ContentManagement.WebControls

Public Class XMLPlaceholderControl
   Inherits BasePlaceholderControl

   Private HeaderText As New TextBox
   Private HeaderLink As New HyperLink
   Private BodyText As New TextBox
   Private BodyLabel As New Label
   Private lit As Literal

   Protected Overrides Sub CreateAuthoringChildControls(ByVal authoringContainer As Microsoft.ContentManagement.WebControls.BaseModeContainer)

       lit = New Literal
       lit.Text = "<table border=0 cellspacing=0 cellpadding=0 width=50%><tr id=headTR valign=top><td width=100% align=left>"
       authoringContainer.Controls.Add(Me.lit)

       With Me.HeaderText
           .ID = "txtHead"
           .Width = Unit.Percentage(100)
       End With
       authoringContainer.Controls.Add(Me.HeaderText)

       lit = New Literal
       lit.Text = "</td></tr><tr id=bodyTR valign=top><td width=100% align=left>"
       authoringContainer.Controls.Add(Me.lit)

       With BodyText
           .ID = "txtBody"
           .TextMode = TextBoxMode.MultiLine
           .Rows = 5
           .Wrap = True
           .Width = Unit.Percentage(100)
       End With
       authoringContainer.Controls.Add(Me.BodyText)

       lit = New Literal
       lit.Text = "</td></tr></table>"
       authoringContainer.Controls.Add(Me.lit)
   End Sub

   Protected Overrides Sub CreatePresentationChildControls(ByVal presentationContainer As Microsoft.ContentManagement.WebControls.BaseModeContainer)
       lit = New Literal
       With lit
           .Text = "<script language=""javascript"" src=""classes.js"" type=""text/javascript""></script>"
       End With
       presentationContainer.Controls.Add(Me.lit)

       lit = New Literal
       lit.Text = "<table border=0 cellspacing=0 cellpadding=0 width=50%><tr id=headTR valign=top><td width=100% align=left>"
       presentationContainer.Controls.Add(Me.lit)

       With Me.HeaderLink
           .ID = "lnkHead"
           .Width = Unit.Percentage(100)
           .NavigateUrl = "#"
           .Attributes("onClick") = "toggle('bodyTR')"
           .Text = CType(Me.BoundPlaceholder, XmlPlaceholder).XmlAsString
       End With
       presentationContainer.Controls.Add(Me.HeaderLink)

       lit = New Literal
       lit.Text = "</td></tr><tr id=bodyTR valign=top style=""display:none;""><td width=100% align=left>"
       presentationContainer.Controls.Add(Me.lit)

       With BodyLabel
           .ID = "lblBody"
           .Width = Unit.Percentage(100)
           .Text = CType(Me.BoundPlaceholder, XmlPlaceholder).XmlAsString
       End With
       presentationContainer.Controls.Add(Me.BodyText)

       lit = New Literal
       lit.Text = "</td></tr></table>"
       presentationContainer.Controls.Add(Me.lit)

   End Sub

   Protected Overrides Sub LoadPlaceholderContentForAuthoring(ByVal e As Microsoft.ContentManagement.WebControls.PlaceholderControlEventArgs)
       Me.EnsureChildControls()
       Try
           Me.HeaderText.Text = "-- Title --"
           Me.BodyText.Text = "-- Description --"
       Catch ex As Exception
           Throw (New Exception("Error Loading Authoring Contorls", ex))
       End Try

   End Sub

   Protected Overrides Sub LoadPlaceholderContentForPresentation(ByVal e As Microsoft.ContentManagement.WebControls.PlaceholderControlEventArgs)
       Me.EnsureChildControls()
       Try
           Me.HeaderLink.Text = CType(Me.BoundPlaceholder, XmlPlaceholder).XmlAsString
           Me.BodyLabel.Text = CType(Me.BoundPlaceholder, XmlPlaceholder).XmlAsString
       Catch ex As Exception
           Me.HeaderLink.Text = "Unable to load text"
       End Try
   End Sub

   Protected Overrides Sub SavePlaceholderContent(ByVal e As Microsoft.ContentManagement.WebControls.PlaceholderControlSaveEventArgs)
       Me.EnsureChildControls()
       Try
           CType(Me.BoundPlaceholder, XmlPlaceholder).XmlAsString = Me.HeaderText.Text
           CType(Me.BoundPlaceholder, XmlPlaceholder).XmlAsString = Me.BodyText.Text
       Catch ex As Exception
           Dim errMsg As String = "Unable to save text"
           Throw (New Exception(errMsg, ex))
       End Try
   End Sub
End Class

 

FYI, this custom placeholder is bind to XMLPlaceholderDefinition. The error occurs when I click on 'Preview' or 'Save New Page'.

 

I suspect something wrong with my SavePlaceholderContent method implementation but I'm not sure how to fix it. Or probably, because I have multiple server controls in this single custom placeholder?

 

Please help me if anyone have experience with MCMS 2002. Thanks!!!

Nothing is impossible in Programming! So, take it easy and let us all share your problem. :)
Posted
Oh guys, I solved the problem. I should have save the contents as XML document with each component's text as seperate XML element. Thanks.
Nothing is impossible in Programming! So, take it easy and let us all share your problem. :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...