|
Home > Archive > Microsoft Content Management Server > November 2004 > Placeholders inside Custom Control wont save
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Placeholders inside Custom Control wont save
|
|
| Simon F. 2004-11-26, 2:46 am |
| I've created a custom control that contains a number of CMS placeholders.
When I place the control in a template aspx file, the contents of the
placeholders are rendered OK in presentation mode, I can change the content
in edit mode, but when I try to save the changes they are lost and the
placeholders revert to their original content.
If I put a place holder directly on the same template in the normal manner,
its content will save OK.
The custom control is contained in the web project.
Is there something I need to do to tie the custom control to the page?
| |
| Jakub Skopal 2004-11-26, 2:46 am |
| Hello Simon,
I'm using placeholders deeply nested into ASCXes and WebControls and
have no problems. Maybe there's something non-standard about your custom
control that interferes...
Rules are:
* construct the placeholder always in CreateChildControls() of the
control (or place it into ASCX)
* place the placeholder into the control every time to the same
place, even if you don't want to display it at all. transitions between
presentation and authoring mode require consistent viewstate. If you
don't want to display the placeholder, set it's Visible property to false.
cannot think of any else. If you post sourcecode for your control, I
might be able to help more.
Jakub
Simon F. wrote:
> I've created a custom control that contains a number of CMS placeholders.
>
> When I place the control in a template aspx file, the contents of the
> placeholders are rendered OK in presentation mode, I can change the content
> in edit mode, but when I try to save the changes they are lost and the
> placeholders revert to their original content.
>
> If I put a place holder directly on the same template in the normal manner,
> its content will save OK.
>
> The custom control is contained in the web project.
>
>
> Is there something I need to do to tie the custom control to the page?
>
>
| |
| Angus Logan [MVP] 2004-11-26, 2:46 am |
| Hi Simon,
ARe you able to post the code?
Regards
--
________________________________________
Angus Logan (MCAD/MCDBA/MCP/MVP for MCMS)
Product Specialist
Microsoft Application Solutions
Data#3 Limited
E angus_logan@data3.com.au
BLOG www.anguslogan.com
________________________________________
"Simon F." <Simon F.@discussions.microsoft.com> wrote in message
news:FF1F4381-F6A3-4DD4-8F97-E48E83637FBB@microsoft.com...
> I've created a custom control that contains a number of CMS placeholders.
>
> When I place the control in a template aspx file, the contents of the
> placeholders are rendered OK in presentation mode, I can change the
> content
> in edit mode, but when I try to save the changes they are lost and the
> placeholders revert to their original content.
>
> If I put a place holder directly on the same template in the normal
> manner,
> its content will save OK.
>
> The custom control is contained in the web project.
>
>
> Is there something I need to do to tie the custom control to the page?
>
>
| |
| Stefan [MSFT] 2004-11-26, 5:49 pm |
| Hi Simon,
please have a look in this article:
http://download.microsoft.com/downl...6a/MCMS+2002+-+(complete)+FAQ.htm#FBCAE7EE-AE3F-4F1E-B017-2ECD03749FA3
Cheers,
Stefan.
"Simon F." <Simon F.@discussions.microsoft.com> wrote in message
news:FF1F4381-F6A3-4DD4-8F97-E48E83637FBB@microsoft.com...
> I've created a custom control that contains a number of CMS placeholders.
>
> When I place the control in a template aspx file, the contents of the
> placeholders are rendered OK in presentation mode, I can change the
content
> in edit mode, but when I try to save the changes they are lost and the
> placeholders revert to their original content.
>
> If I put a place holder directly on the same template in the normal
manner,
> its content will save OK.
>
> The custom control is contained in the web project.
>
>
> Is there something I need to do to tie the custom control to the page?
>
>
| |
|
| I've included the source code.
I did notice one error in my original post, I meant to say that the custom
control is NOT in the web project.
I've check that there is only one set of form tags and that all of the
placeholders appear between them and it all looks OK. The placeholders are
being generated out of the CreateChildControls() and should be being created
every time the page is.
Here's the source. Its long-ish
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports Microsoft.ContentManagement.Publishing
Imports Microsoft.ContentManagement.WebControls
<DefaultProperty("Text"), ToolboxData("<{0}:CfgTmp_Left_Nav_Type_001
runat=server></{0}:CfgTmp_Left_Nav_Type_001>")> Public Class
CfgTmp_Left_Nav_Type_001
Inherits System.Web.UI.WebControls.WebControl
Dim _text As String
<Bindable(True), Category("Appearance"), DefaultValue("")> Property
[Text]() As String
Get
Return _text
End Get
Set(ByVal Value As String)
_text = Value
End Set
End Property
Protected Overrides Sub RenderContents(ByVal writer As
System.Web.UI.HtmlTextWriter)
If Not Me.Site Is Nothing Then
'Design mode
Dim dControlStr As String = "<div
style='background-color:lightgrey;font-family:verdana,arial;font-size:10px;font-weight:bold;padding:5px;'>" _
& Me.getType.Name & " - " & Me.ClientID.ToString & "</div>"
writer.Write(dControlStr)
Else
'Runtime mode
MyBase.RenderContents(writer)
End If
End Sub
Protected Overrides Sub CreateChildControls()
'Main Table
Dim mainTable As New Table()
Dim row As TableRow
Dim cell As TableCell
'Render the Navigation Configuration Placeholders
row = New TableRow()
cell = New TableCell()
'cell.Controls. Add(BuildConfigurationTable(BuildBoolean
PlaceHolderList))
row.Cells.Add(cell)
mainTable.Rows.Add(row)
'Render the Navigation Image Placholders
row = New TableRow()
cell = New TableCell()
cell.Controls. Add(BuildImageTable(BuildImagePlaceholde
rList))
row.Cells.Add(cell)
mainTable.Rows.Add(row)
Me.Controls.Add(mainTable)
End Sub
Private Function BuildConfigurationTable(ByVal BooleanPlaceHolderList As
Collection)
Dim ConfigTable As New Table()
Dim row As TableRow
Dim cell As TableCell
Dim phSummary As PlaceHolderSummary
For Each phSummary In BooleanPlaceHolderList
row = New TableRow()
cell = New TableCell()
cell.Controls. Add(BuildBooleanPlaceHolderTable(phSumma
ry))
row.Cells.Add(cell)
ConfigTable.Rows.Add(row)
Next
Return ConfigTable
End Function
Private Function BuildBooleanPlaceHolderTable(ByVal phSummary As
PlaceHolderSummary) As Table
Dim Table As New Table()
Dim row As New TableRow()
Dim cell As TableCell
cell = New TableCell()
Dim currentBlnPlaceholder As New BooleanPlaceholder()
currentBlnPlaceholder.PlaceholderToBind = phSummary.PlaceHolderName
cell.Controls.Add(currentBlnPlaceholder)
row.Cells.Add(cell)
cell = New TableCell()
Dim currentPhLabel As New Label()
currentPhLabel.Text = phSummary.Title
cell.Controls.Add(currentPhLabel)
row.Cells.Add(cell)
Table.Rows.Add(row)
Return Table
End Function
Private Function BuildBooleanPlaceHolderList() As Collection
Dim PhCollection As New Collection()
Dim phSummary As PlaceHolderSummary
'Populate placeholder details
phSummary = New PlaceHolderSummary("ShowEmptyChannels", _
"Show Empty Channels", _
"")
PhCollection.Add(phSummary)
'...More like this...
Return PhCollection
End Function
Private Function BuildImagePlaceholderList() As Collection
Dim PhCollection As New Collection()
Dim phSummary As PlaceHolderSummary
'Populate placeholder details
phSummary = New PlaceHolderSummary("NavigationPopoutImage", _
"Navigation Popout Image", _
"")
PhCollection.Add(phSummary)
'...More like this...
Return PhCollection
End Function
Private Function BuildImageTable(ByVal phSummaryCollection As
Collection) As Table
Dim imageTable As New Table()
Dim phSummary As PlaceHolderSummary
Dim phSummaryLeft As PlaceHolderSummary
Dim phSummaryRight As PlaceHolderSummary
Dim rowMax As Integer = 2
Dim rowCount As Integer = 0
For Each phSummary In phSummaryCollection
rowCount += 1
Select Case rowCount
Case 1
phSummaryLeft = phSummary
Case 2
phSummaryRight = phSummary
imageTable.Rows.Add(BuildImageRow(phSummaryLeft,
phSummaryRight))
rowCount = 0
End Select
Next
Return imageTable
End Function
Private Function BuildImageRow(ByVal LeftPlaceHolder As
PlaceHolderSummary, _
ByVal RightPlaceHolder As
PlaceHolderSummary) As TableRow
Dim row As New TableRow()
Dim cell As TableCell
cell = New TableCell()
cell.Controls. Add(BuildImagePlaceholderTable(LeftPlace
Holder))
row.Cells.Add(cell)
cell = New TableCell()
cell.Controls. Add(BuildImagePlaceholderTable(RightPlac
eHolder))
row.Cells.Add(cell)
Return row
End Function
Private Function BuildImagePlaceholderTable(ByVal CurrentPlaceHolder As
PlaceHolderSummary) As Table
Dim table As New Table()
Dim row As TableRow
Dim cell As TableCell
If Not CurrentPlaceHolder.PlaceHolderName = String.Empty Then
Dim nameLabel As New Label()
nameLabel.Text = CurrentPlaceHolder.Title
Dim descriptionLabel As New Label()
descriptionLabel.Text = CurrentPlaceHolder.Description
Dim phImageControl As New SingleImagePlaceholderControl()
phImageControl.PlaceholderToBind =
CurrentPlaceHolder.PlaceHolderName
'Title Row
row = New TableRow()
cell = New TableCell()
cell.Controls.Add(nameLabel)
row.Cells.Add(cell)
table.Rows.Add(row)
'Description Row
row = New TableRow()
cell = New TableCell()
cell.Controls.Add(descriptionLabel)
row.Cells.Add(cell)
table.Rows.Add(row)
'Placeholder Row
row = New TableRow()
cell = New TableCell()
cell.Controls.Add(phImageControl)
row.Cells.Add(cell)
table.Rows.Add(row)
Else
'Insert an empty table
row = New TableRow()
cell = New TableCell()
row.Cells.Add(cell)
table.Rows.Add(row)
End If
Return table
End Function
Private Class PlaceHolderSummary
Public PlaceHolderName As String
Public Title As String
Public Description As String
Public Sub New(ByVal PlaceHolderName As String, ByVal Title As
String, ByVal Description As String)
Me.PlaceHolderName = PlaceHolderName
Me.Title = Title
Me.Description = Description
End Sub
End Class
End Class
"Jakub Skopal" wrote:
> Hello Simon,
>
> I'm using placeholders deeply nested into ASCXes and WebControls and
> have no problems. Maybe there's something non-standard about your custom
> control that interferes...
>
> Rules are:
> * construct the placeholder always in CreateChildControls() of the
> control (or place it into ASCX)
> * place the placeholder into the control every time to the same
> place, even if you don't want to display it at all. transitions between
> presentation and authoring mode require consistent viewstate. If you
> don't want to display the placeholder, set it's Visible property to false.
>
> cannot think of any else. If you post sourcecode for your control, I
> might be able to help more.
>
> Jakub
>
> Simon F. wrote:
>
| |
| Stefan [MSFT] 2004-11-29, 7:50 am |
| Hi Simon,
please use the code in the following sample to dynamically bind placeholder
controls:
http://www.gotdotnet.com/Community/...d5-0a610ebda849
Cheers,
Stefan.
"Simon" <Simon@discussions.microsoft.com> wrote in message
news:A1E455D2-F969-44C5-BA82-CE693DAD1A80@microsoft.com...
> I've included the source code.
>
> I did notice one error in my original post, I meant to say that the custom
> control is NOT in the web project.
>
> I've check that there is only one set of form tags and that all of the
> placeholders appear between them and it all looks OK. The placeholders are
> being generated out of the CreateChildControls() and should be being
created
> every time the page is.
>
> Here's the source. Its long-ish
>
> Imports System.ComponentModel
> Imports System.Web.UI
> Imports System.Web.UI.WebControls
> Imports Microsoft.ContentManagement.Publishing
> Imports Microsoft.ContentManagement.WebControls
>
>
>
> <DefaultProperty("Text"), ToolboxData("<{0}:CfgTmp_Left_Nav_Type_001
> runat=server></{0}:CfgTmp_Left_Nav_Type_001>")> Public Class
> CfgTmp_Left_Nav_Type_001
> Inherits System.Web.UI.WebControls.WebControl
>
> Dim _text As String
>
> <Bindable(True), Category("Appearance"), DefaultValue("")> Property
> [Text]() As String
> Get
> Return _text
> End Get
>
> Set(ByVal Value As String)
> _text = Value
> End Set
> End Property
>
> Protected Overrides Sub RenderContents(ByVal writer As
> System.Web.UI.HtmlTextWriter)
> If Not Me.Site Is Nothing Then
> 'Design mode
> Dim dControlStr As String = "<div
>
style='background-color:lightgrey;font-family:verdana,arial;font-size:10px;f
ont-weight:bold;padding:5px;'>" _
> & Me.getType.Name & " - " & Me.ClientID.ToString &
"</div>"
> writer.Write(dControlStr)
> Else
> 'Runtime mode
> MyBase.RenderContents(writer)
> End If
> End Sub
>
>
> Protected Overrides Sub CreateChildControls()
>
> 'Main Table
> Dim mainTable As New Table()
> Dim row As TableRow
> Dim cell As TableCell
>
> 'Render the Navigation Configuration Placeholders
> row = New TableRow()
> cell = New TableCell()
>
> 'cell.Controls. Add(BuildConfigurationTable(BuildBoolean
PlaceHolderList))
> row.Cells.Add(cell)
> mainTable.Rows.Add(row)
>
>
> 'Render the Navigation Image Placholders
> row = New TableRow()
> cell = New TableCell()
> cell.Controls. Add(BuildImageTable(BuildImagePlaceholde
rList))
> row.Cells.Add(cell)
> mainTable.Rows.Add(row)
>
> Me.Controls.Add(mainTable)
>
> End Sub
>
> Private Function BuildConfigurationTable(ByVal BooleanPlaceHolderList
As
> Collection)
> Dim ConfigTable As New Table()
> Dim row As TableRow
> Dim cell As TableCell
>
> Dim phSummary As PlaceHolderSummary
> For Each phSummary In BooleanPlaceHolderList
> row = New TableRow()
> cell = New TableCell()
> cell.Controls. Add(BuildBooleanPlaceHolderTable(phSumma
ry))
> row.Cells.Add(cell)
> ConfigTable.Rows.Add(row)
> Next
>
> Return ConfigTable
>
> End Function
>
> Private Function BuildBooleanPlaceHolderTable(ByVal phSummary As
> PlaceHolderSummary) As Table
>
> Dim Table As New Table()
> Dim row As New TableRow()
> Dim cell As TableCell
>
> cell = New TableCell()
> Dim currentBlnPlaceholder As New BooleanPlaceholder()
> currentBlnPlaceholder.PlaceholderToBind =
phSummary.PlaceHolderName
> cell.Controls.Add(currentBlnPlaceholder)
> row.Cells.Add(cell)
>
> cell = New TableCell()
> Dim currentPhLabel As New Label()
> currentPhLabel.Text = phSummary.Title
> cell.Controls.Add(currentPhLabel)
> row.Cells.Add(cell)
>
> Table.Rows.Add(row)
>
> Return Table
>
> End Function
>
> Private Function BuildBooleanPlaceHolderList() As Collection
> Dim PhCollection As New Collection()
> Dim phSummary As PlaceHolderSummary
>
> 'Populate placeholder details
> phSummary = New PlaceHolderSummary("ShowEmptyChannels", _
> "Show Empty Channels", _
> "")
> PhCollection.Add(phSummary)
>
> '...More like this...
>
> Return PhCollection
>
> End Function
>
> Private Function BuildImagePlaceholderList() As Collection
>
> Dim PhCollection As New Collection()
> Dim phSummary As PlaceHolderSummary
>
>
> 'Populate placeholder details
> phSummary = New PlaceHolderSummary("NavigationPopoutImage", _
> "Navigation Popout Image", _
> "")
> PhCollection.Add(phSummary)
>
>
> '...More like this...
>
> Return PhCollection
>
> End Function
>
> Private Function BuildImageTable(ByVal phSummaryCollection As
> Collection) As Table
> Dim imageTable As New Table()
>
> Dim phSummary As PlaceHolderSummary
> Dim phSummaryLeft As PlaceHolderSummary
> Dim phSummaryRight As PlaceHolderSummary
> Dim rowMax As Integer = 2
> Dim rowCount As Integer = 0
>
> For Each phSummary In phSummaryCollection
> rowCount += 1
> Select Case rowCount
> Case 1
> phSummaryLeft = phSummary
> Case 2
> phSummaryRight = phSummary
> imageTable.Rows.Add(BuildImageRow(phSummaryLeft,
> phSummaryRight))
> rowCount = 0
> End Select
> Next
>
> Return imageTable
>
> End Function
>
> Private Function BuildImageRow(ByVal LeftPlaceHolder As
> PlaceHolderSummary, _
> ByVal RightPlaceHolder As
> PlaceHolderSummary) As TableRow
>
> Dim row As New TableRow()
> Dim cell As TableCell
>
> cell = New TableCell()
> cell.Controls. Add(BuildImagePlaceholderTable(LeftPlace
Holder))
> row.Cells.Add(cell)
>
> cell = New TableCell()
> cell.Controls. Add(BuildImagePlaceholderTable(RightPlac
eHolder))
> row.Cells.Add(cell)
>
> Return row
>
> End Function
>
>
> Private Function BuildImagePlaceholderTable(ByVal CurrentPlaceHolder
As[vbcol=seagreen]
> PlaceHolderSummary) As Table
>
> Dim table As New Table()
> Dim row As TableRow
> Dim cell As TableCell
>
> If Not CurrentPlaceHolder.PlaceHolderName = String.Empty Then
>
> Dim nameLabel As New Label()
> nameLabel.Text = CurrentPlaceHolder.Title
> Dim descriptionLabel As New Label()
> descriptionLabel.Text = CurrentPlaceHolder.Description
> Dim phImageControl As New SingleImagePlaceholderControl()
> phImageControl.PlaceholderToBind =
> CurrentPlaceHolder.PlaceHolderName
>
> 'Title Row
> row = New TableRow()
> cell = New TableCell()
> cell.Controls.Add(nameLabel)
> row.Cells.Add(cell)
> table.Rows.Add(row)
>
> 'Description Row
> row = New TableRow()
> cell = New TableCell()
> cell.Controls.Add(descriptionLabel)
> row.Cells.Add(cell)
> table.Rows.Add(row)
>
> 'Placeholder Row
> row = New TableRow()
> cell = New TableCell()
>
> cell.Controls.Add(phImageControl)
> row.Cells.Add(cell)
> table.Rows.Add(row)
> Else
> 'Insert an empty table
> row = New TableRow()
> cell = New TableCell()
> row.Cells.Add(cell)
> table.Rows.Add(row)
> End If
>
> Return table
>
> End Function
>
> Private Class PlaceHolderSummary
>
> Public PlaceHolderName As String
> Public Title As String
> Public Description As String
>
> Public Sub New(ByVal PlaceHolderName As String, ByVal Title As
> String, ByVal Description As String)
> Me.PlaceHolderName = PlaceHolderName
> Me.Title = Title
> Me.Description = Description
> End Sub
>
> End Class
>
>
> End Class
>
> "Jakub Skopal" wrote:
>
false.[vbcol=seagreen]
placeholders.[vbcol=seagreen]
content[vbcol=seagreen]
manner,[vbcol=seagreen]
| |
| Simon F 2004-11-30, 2:46 am |
| Hi Stefan
The only bits I hadn't done were to set the placeholder control id and do
the databind. I've now included these now, but still no joy.
After I click "save" all of the image placeholders are reappearing with a
broken image in them, but nothing is saved. After exiting, all of the
original images are back in their placeholders.
I suspect that CMS is not parsing the placeholders properly on the save
event, and that this is somehow related to the way the placholders are
imbedded in the custom web control. But I'm still lost as to how to fix the
problem.
Simon
"Stefan [MSFT]" wrote:
> Hi Simon,
>
> please use the code in the following sample to dynamically bind placeholder
> controls:
> http://www.gotdotnet.com/Community/...d5-0a610ebda849
>
> Cheers,
> Stefan.
>
>
> "Simon" <Simon@discussions.microsoft.com> wrote in message
> news:A1E455D2-F969-44C5-BA82-CE693DAD1A80@microsoft.com...
> created
> style='background-color:lightgrey;font-family:verdana,arial;font-size:10px;f
> ont-weight:bold;padding:5px;'>" _
> "</div>"
> As
> phSummary.PlaceHolderName
> As
> false.
> placeholders.
> content
> manner,
>
>
>
|
|
|
|
|