Hi, and thanks for the reply. The reason I am checking the header template has an instance is because I am not forcing the designer to use a header template. They have the option to leave that out.
I should have also mentioned that I have overriden the render routine like this:
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
' This anchor is used to allow a given collapsing panel to be
' navigated to on the page
Dim anchor As New LiteralControl(String.Format("<a name='{0}_anchor'></a>", ID))
anchor.RenderControl(writer)
updatePanel.RenderControl(writer)
End Sub
I add all my controls to the updatePanel then render that. I have also tried just adding the update panel to the root control. Both work, just no viewstate for anything :(
I'm attaching the full code for the panel. Sorry, but it is long...
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design.WebControls
Namespace Curve.WebControls
<DefaultProperty("Text")> _
<ToolboxData("<{0}:CollapsingPanel runat=server></{0}:CollapsingPanel>")> _
<Designer(GetType(CollapsingPanelDesigner))> _
<ParseChildren(True, "ContentTemplate")> _
<PersistChildren(True)> _
Public Class CollapsingPanel
Inherits Panel
'Implements INamingContainer
Public Event CloseButtonClicked(ByRef self As CollapsingPanel)
#Region " Variables "
Private header As ITemplate
Private content As ITemplate
Private headerTemplateContainer As CollapsingPanelTemplateContainer
Private contentTemplateContainer As CollapsingPanelTemplateContainer
Private updatePanel As UpdatePanel
Private collapseStateTextBox As TextBox
Private expandAnimation As AjaxControlToolkit.AnimationExtender
Private collapseAnimation As AjaxControlToolkit.AnimationExtender
Private mainPanel As Panel
Private titlePanel As Panel
Private bodyPanel As Panel
Private bodyInnerPanel As Panel
Private titleLabel As Label
Private refreshButton As ImageButton
Private collapseButton As ImageButton
Private expandButton As ImageButton
Private closeButton As ImageButton
Private titleTable As Table
Private tr As TableRow
Private titleLabelCell As TableCell
Private titleButtonsCell As TableCell
Private refreshSpacer As LiteralControl
Private collapseSpacer As LiteralControl
Private closeSpacer As LiteralControl
#End Region
#Region " Properties "
<PersistenceMode(PersistenceMode.InnerProperty)> _
<TemplateContainer(GetType(CollapsingPanelTemplateContainer))> _
<TemplateInstance(TemplateInstance.Single)> _
Public Property HeaderTemplate() As ITemplate
Get
Return header
End Get
Set(ByVal value As ITemplate)
header = value
End Set
End Property
<PersistenceMode(PersistenceMode.InnerProperty)> _
<TemplateContainer(GetType(CollapsingPanelTemplateContainer))> _
<TemplateInstance(TemplateInstance.Single)> _
Public Property ContentTemplate() As ITemplate
Get
Return content
End Get
Set(ByVal value As ITemplate)
content = value
End Set
End Property
<Bindable(True)> _
<Category("Appearance")> _
<DefaultValue("")> _
<Localizable(True)> _
Public Property Title() As String
Get
Dim s As String = ViewState("Title")
Return IIf(s = Nothing, String.Empty, s)
End Get
Set(ByVal value As String)
ViewState("Title") = value
If titleLabel IsNot Nothing Then
titleLabel.Text = value
End If
End Set
End Property
<Bindable(True)> _
<Category("Appearance")> _
<DefaultValue("")> _
<Localizable(True)> _
Public Property IsCollapsed() As Boolean
Get
Dim s As String = ViewState("IsCollapsed")
'Dim s As String = Me.Context.Items(Me.ID & "$IsCollapsed")
Return IIf(s = Nothing, False, Convert.ToBoolean(s))
End Get
Set(ByVal value As Boolean)
ViewState("IsCollapsed") = value.ToString
End Set
End Property
<Bindable(True)> _
<Category("Appearance")> _
<DefaultValue("")> _
<Localizable(True)> _
Public Property IsCollapsible() As Boolean
Get
Dim s As String = ViewState("IsCollapsible")
Return IIf(s = Nothing, False, Convert.ToBoolean(s))
End Get
Set(ByVal value As Boolean)
ViewState("IsCollapsible") = value.ToString
End Set
End Property
<Bindable(True)> _
<Category("Appearance")> _
<DefaultValue("")> _
<Localizable(True)> _
Public Property IsRefreshable() As Boolean
Get
Dim s As String = ViewState("IsRefreshable")
Return IIf(s = Nothing, False, Convert.ToBoolean(s))
End Get
Set(ByVal value As Boolean)
ViewState("IsRefreshable") = value
If refreshButton IsNot Nothing Then
refreshButton.Visible = value
End If
End Set
End Property
<Bindable(True)> _
<Category("Appearance")> _
<DefaultValue("")> _
<Localizable(True)> _
Public Property IsClosable() As Boolean
Get
Dim s As String = ViewState("IsClosable")
Return IIf(s = Nothing, False, Convert.ToBoolean(s))
End Get
Set(ByVal value As Boolean)
ViewState("IsClosable") = value.ToString
If closeButton IsNot Nothing Then
closeButton.Visible = value
End If
End Set
End Property
<Bindable(True)> _
<Category("Appearance")> _
<DefaultValue("")> _
<Localizable(True)> _
Public Property IsChildViewStateEnabled() As Boolean
Get
Dim s As String = ViewState("IsChildViewStateEnabled")
Return IIf(s = Nothing, True, Convert.ToBoolean(s))
End Get
Set(ByVal value As Boolean)
ViewState("IsChildViewStateEnabled") = value
End Set
End Property
#End Region
#Region " Overrides "
Protected Overrides Sub OnInit(ByVal e As EventArgs)
MyBase.OnInit(e)
EnsureChildControls()
Me.TrackViewState()
If collapseStateTextBox.Text = "True" Then
Me.CollapsePanel()
Else
Me.OpenPanel()
End If
End Sub
Protected Overrides Sub CreateChildControls()
Controls.Clear()
updatePanel = New UpdatePanel
Controls.Add(updatePanel)
mainPanel = New Panel
updatePanel.ContentTemplateContainer.Controls.Add(mainPanel)
collapseStateTextBox = New TextBox
mainPanel.Controls.Add(collapseStateTextBox)
titlePanel = New Panel
mainPanel.Controls.Add(titlePanel)
titleTable = New Table
titlePanel.Controls.Add(titleTable)
tr = New TableRow
titleTable.Rows.Add(tr)
titleLabelCell = New TableCell
tr.Cells.Add(titleLabelCell)
titleLabel = New Label
headerTemplateContainer = New CollapsingPanelTemplateContainer
titleLabelCell.Controls.Add(headerTemplateContainer)
If HeaderTemplate IsNot Nothing Then HeaderTemplate.InstantiateIn(headerTemplateContainer)
If headerTemplateContainer.Controls.Count <= 1 Then
headerTemplateContainer.Controls.Add(titleLabel)
End If
titleButtonsCell = New TableCell
tr.Cells.Add(titleButtonsCell)
refreshSpacer = New LiteralControl(" ")
titleButtonsCell.Controls.Add(refreshSpacer)
refreshButton = New ImageButton
titleButtonsCell.Controls.Add(refreshButton)
collapseSpacer = New LiteralControl(" ")
titleButtonsCell.Controls.Add(collapseSpacer)
collapseButton = New ImageButton
titleButtonsCell.Controls.Add(collapseButton)
collapseAnimation = New AjaxControlToolkit.AnimationExtender
titleButtonsCell.Controls.Add(collapseAnimation)
expandButton = New ImageButton
titleButtonsCell.Controls.Add(expandButton)
expandAnimation = New AjaxControlToolkit.AnimationExtender
titleButtonsCell.Controls.Add(expandAnimation)
closeSpacer = New LiteralControl(" ")
titleButtonsCell.Controls.Add(closeSpacer)
closeButton = New ImageButton
titleButtonsCell.Controls.Add(closeButton)
bodyPanel = New Panel
mainPanel.Controls.Add(bodyPanel)
bodyInnerPanel = New Panel
bodyPanel.Controls.Add(bodyInnerPanel)
' Add controls to bodyInnerPanel
contentTemplateContainer = New CollapsingPanelTemplateContainer
bodyInnerPanel.Controls.Add(contentTemplateContainer)
If ContentTemplate IsNot Nothing Then
ContentTemplate.InstantiateIn(contentTemplateContainer)
End If
' Disable viewstate in all controls?
If Not IsChildViewStateEnabled Then
DisableViewState(Me)
End If
' Set all the values and properties
ConfigureInternalLayoutControls()
ChildControlsCreated = True
End Sub
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
' This anchor is used to allow a given collapsing panel to be
' navigated to on the page
Dim anchor As New LiteralControl(String.Format("<a name='{0}_anchor'></a>", ID))
anchor.RenderControl(writer)
'mainPanel.RenderControl(writer)
updatePanel.RenderControl(writer)
End Sub
#End Region
#Region " Events "
Public Sub refreshButton_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
updatePanel.Update()
End Sub
Protected Sub closeButton_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
RaiseEvent CloseButtonClicked(Me)
End Sub
#End Region
#Region " Custom Methods "
''' <summary>
''' Recursive function to disable viewstate on control and all of its children.
''' </summary>
''' <param name="c"></param>
''' <remarks></remarks>
Private Sub DisableViewState(ByVal c As Control)
'c.EnableViewState = False
'For Each sc As Control In c.Controls
' sc.EnableViewState = False
' If sc.HasControls Then
' DisableViewState(sc)
' End If
'Next
End Sub
Private Sub ConfigureInternalLayoutControls()
'If Me.IsRefreshable Then
updatePanel.UpdateMode = UpdatePanelUpdateMode.Conditional
'Else
' updatePanel.UpdateMode = UpdatePanelUpdateMode.Always
'End If
mainPanel.CssClass = "panel_container_group"
mainPanel.Width = Me.Width
bodyPanel.Width = Me.Width
bodyPanel.Height = Me.Height
'bodyPanel.ScrollBars = Me.ScrollBars
titlePanel.CssClass = "panel_container_header"
titleTable.Width = New Unit(100, UnitType.Percentage)
titleLabel.Text = Title
titleButtonsCell.HorizontalAlign = HorizontalAlign.Right
titleButtonsCell.VerticalAlign = VerticalAlign.Middle
refreshSpacer.Visible = IsRefreshable
refreshButton.ImageUrl = "~/client/site_layout/icons/container_refresh.png"
AddHandler refreshButton.Click, AddressOf Me.refreshButton_Click
refreshButton.Visible = IsRefreshable
collapseSpacer.Visible = IsCollapsible
collapseButton.ImageUrl = "~/client/site_layout/icons/container_collapse.png"
collapseButton.ToolTip = "Collapse"
collapseButton.Visible = IsCollapsible
collapseAnimation.TargetControlID = collapseButton.UniqueID
collapseAnimation.Animations = GetCollapseAnimationXml()
expandButton.ImageUrl = "~/client/site_layout/icons/container_expand.png"
expandButton.ToolTip = "Expand"
expandButton.Visible = IsCollapsible
expandAnimation.TargetControlID = expandButton.UniqueID
expandAnimation.Animations = GetExpandAnimationXml()
If Not Me.Page.IsPostBack Then
collapseStateTextBox.Text = IsCollapsed
End If
If IsCollapsible Then
If IsCollapsed Then
collapseButton.Style("display") = "none"
expandButton.Style("display") = "inline"
bodyPanel.Style("display") = "none"
Else
collapseButton.Style("display") = "inline"
expandButton.Style("display") = "none"
bodyPanel.Style("display") = "block"
End If
End If
closeSpacer.Visible = IsClosable
closeButton.ImageUrl = "~/client/site_layout/icons/container_close.png"
closeButton.ToolTip = "Close"
closeButton.OnClientClick = "return confirm('Are you sure you want to close this panel?');"
AddHandler closeButton.Click, AddressOf Me.closeButton_Click
closeButton.Visible = IsClosable
'If CloseConfirmation IsNot Nothing AndAlso CloseConfirmation.Trim <> "" Then
' closeButton.OnClientClick = "var close = confirm('" & CloseConfirmation & "'); if (! close) {return false;}"
'End If
bodyPanel.CssClass = "panel_container"
bodyInnerPanel.CssClass = "panel_container_inner"
collapseStateTextBox.Style.Add("display", "none")
collapseStateTextBox.Visible = True
expandButton.Attributes.Add("onclick", String.Format("{0}.value = 'False';return false;", collapseStateTextBox.ClientID))
collapseButton.Attributes.Add("onclick", String.Format("{0}.value = 'True';return false;", collapseStateTextBox.ClientID))
End Sub
Private Function GetCollapseAnimationXml() As String
Dim sb As New IO.StringWriter
sb.WriteLine("<OnClick>")
sb.WriteLine(" <Parallel Duration="".2"" Fps=""40"">")
sb.WriteLine(" <StyleAction AnimationTarget=""{0}"" Attribute=""display"" Value=""none"" />", collapseButton.UniqueID)
sb.WriteLine(" <StyleAction AnimationTarget=""{0}"" Attribute=""display"" Value=""inline"" />", expandButton.UniqueID)
sb.WriteLine(" <StyleAction AnimationTarget=""{0}"" Attribute=""display"" Value=""none"" />", bodyPanel.UniqueID)
sb.WriteLine(" </Parallel>")
sb.WriteLine("</OnClick>")
Return sb.ToString
End Function
Private Function GetExpandAnimationXml() As String
Dim sb As New IO.StringWriter
sb.WriteLine("<OnClick>")
sb.WriteLine(" <Parallel Duration="".2"" Fps=""40"">")
sb.WriteLine(" <StyleAction AnimationTarget=""{0}"" Attribute=""display"" Value=""none"" />", expandButton.UniqueID)
sb.WriteLine(" <StyleAction AnimationTarget=""{0}"" Attribute=""display"" Value=""inline"" />", collapseButton.UniqueID)
sb.WriteLine(" <StyleAction AnimationTarget=""{0}"" Attribute=""display"" Value=""block"" />", bodyPanel.UniqueID)
sb.WriteLine(" </Parallel>")
sb.WriteLine("</OnClick>")
Return sb.ToString
End Function
Public Sub Update()
updatePanel.Update()
End Sub
Public Sub CollapsePanel()
If IsCollapsible Then
collapseButton.Style("display") = "none"
expandButton.Style("display") = "inline"
bodyPanel.Style("display") = "none"
End If
End Sub
Public Sub OpenPanel()
If IsCollapsible Then
collapseButton.Style("display") = "inline"
expandButton.Style("display") = "none"
bodyPanel.Style("display") = "block"
End If
End Sub
#End Region
End Class
Public Class CollapsingPanelDesigner
Inherits PanelContainerDesigner
Private panel As CollapsingPanel
Public Overrides Sub Initialize(ByVal component As IComponent)
MyBase.Initialize(component)
panel = component
End Sub
Public Overrides ReadOnly Property FrameCaption() As String
Get
Return IIf(panel.Title Is Nothing Or panel.Title.Trim = "", "Collapsible Panel", panel.Title)
End Get
End Property
End Class
<ViewStateModeById()> _
Public Class CollapsingPanelTemplateContainer
Inherits CompositeControl
'Implements INamingContainer
'Private _parent As CollapsingPanel
'Public Sub New(ByVal Parent As CollapsingPanel)
' _parent = Parent
'End Sub
'Public ReadOnly Property CollapsingPanel() As CollapsingPanel
' Get
' Return _parent
' End Get
'End Property
End Class
End Namespace