Answered by:
Persist Viewstate for Children created with ITemplate

Question
-
User1982991741 posted
Hello Coders,
I have a particularly brain frying problem today. I'd appreciate it if you can help before I test how strong the walls of the office are.
I have a custom collapsible panel control which I'm placing some custom web controls. The viewstate of my custom webcontrols is not persisting between postbacks. I think this is because inside my collapsible panel, I override CreateChildControls (to layout my controls from my ITemplate) and OnInit (to call EnsureChildControls).
The Class is defined with the following attributes:
<DefaultProperty("Text")> _ <ToolboxData("<{0}:CollapsingPanel runat=server></{0}:CollapsingPanel>")> _ <Designer(GetType(CollapsingPanelDesigner))> _ <ParseChildren(True)> _ <PersistChildren(True, True)> _
Inside the control, I have a HeaderTemplate and a ContentTemplate which are defined as follows:
<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
Inside the override to CreateChildControls, I have this:headerTemplateContainer = New CollapsingPanelTemplateContainer If HeaderTemplate IsNot Nothing Then HeaderTemplate.InstantiateIn(headerTemplateContainer) headerPanel.Controls.Add(headerTemplateContainer)
I also have something similar for the content template. When I enable my trace for the page, all of the child controls inside the panel have 0 bytes against their viewstate. I have been looking into this all day, and am yet to find a solution. I have tried using the <ViewStateModeById> _ attribute, but still no luck. I have also checked that the controls have the same id over postbacks.If you can help me solve this, you are a genius :)
Thursday, November 12, 2009 10:29 AM
Answers
-
User-16411453 posted
Protected Overrides Sub OnInit(ByVal e As System.EventArgs) MyBase.OnInit(e) Controls.Clear() Dim cs As ClientScriptManager = Me.Page.ClientScript Dim rsType As Type = Me.GetType() Dim Comment As LiteralControl Comment = New LiteralControl Comment.Text = "<!-- PageFooter Control V1.4.2 for ASP.NET -->" & vbCrLf Controls.Add(Comment) Dim UpdatePanel As UpdatePanel UpdatePanel = New UpdatePanel With UpdatePanel End With Controls.Add(UpdatePanel) Dim anchor As LiteralControl anchor = New LiteralControl With anchor .text = String.Format("<a name='{0}_anchor'></a>", ID)) End With UpdatePanel.ContentTemplateContainer.Controls.Add(anchor) End Sub
Here is some sample control code I gave out yesterday. Follow a similar format and it will retain the viewstate
Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Text Imports System.Web Imports System.Web.UI Imports System.Web.UI.WebControls <DefaultProperty("Text"), ToolboxData("<{0}:Display_PageFooter runat=server></{0}:Display_PageFooter>")> _ Public Class Display_PageFooter Inherits WebControl Protected Overrides Sub Render(ByVal writer As HtmlTextWriter) If Not Me.Context Is Nothing Then RenderContents(writer) Else RenderDesignMode(writer) End If End Sub Protected Overrides Sub OnInit(ByVal e As System.EventArgs) MyBase.OnInit(e) Controls.Clear() Dim cs As ClientScriptManager = Me.Page.ClientScript Dim rsType As Type = Me.GetType() Dim Comment As LiteralControl Comment = New LiteralControl Comment.Text = "<!-- PageFooter Control V1.4.2 for ASP.NET -->" & vbCrLf Controls.Add(Comment) Dim table As Table table = New Table With table .CellPadding = 0 .CellSpacing = 0 .Width = 960 .Style.Add(HtmlTextWriterStyle.Width, "960px") End With Controls.Add(table) Dim tr As TableRow tr = New TableRow With tr End With table.Controls.Add(tr) Dim td As TableCell td = New TableCell With td .Height = 30 .Style.Add(HtmlTextWriterStyle.Height, "30px") .Style.Add(HtmlTextWriterStyle.FontFamily, "Tahoma, Verdana, Arial, Helvetica, sans-serif") .Style.Add(HtmlTextWriterStyle.FontSize, "12px") .Style.Add(HtmlTextWriterStyle.Color, "#000000") .Style.Add(HtmlTextWriterStyle.BackgroundImage, cs.GetWebResourceUrl(rsType, "admin.pr_bgDkGray_1x30.gif").ToString) .Style.Add(HtmlTextWriterStyle.FontWeight, "normal") .Style.Add(HtmlTextWriterStyle.TextAlign, "center") .VerticalAlign = VerticalAlign.Middle End With tr.Controls.Add(td) Dim lbl_CopyRight As Label lbl_CopyRight = New Label With lbl_CopyRight .Text = "Copyright (2005-2009)" End With td.Controls.Add(lbl_CopyRight) End Sub Private Sub RenderDesignMode(ByVal writer As HtmlTextWriter) Controls.Clear() Dim cs As ClientScriptManager = Me.Page.ClientScript Dim rsType As Type = Me.GetType() Dim Comment As LiteralControl Comment = New LiteralControl Comment.Text = "<!--PageFooter Control V1.4.2 for ASP.NET -->" & vbCrLf Controls.Add(Comment) Dim table As Table table = New Table With table .CellPadding = 0 .CellSpacing = 0 .Width = 960 .Style.Add(HtmlTextWriterStyle.Width, "960px") End With Controls.Add(table) Dim tr As TableRow tr = New TableRow With tr End With table.Controls.Add(tr) Dim td As TableCell td = New TableCell With td .Height = 30 .Style.Add(HtmlTextWriterStyle.Height, "30px") .Style.Add(HtmlTextWriterStyle.FontFamily, "Tahoma, Verdana, Arial, Helvetica, sans-serif") .Style.Add(HtmlTextWriterStyle.FontSize, "12px") .Style.Add(HtmlTextWriterStyle.Color, "#000000") .Style.Add(HtmlTextWriterStyle.BackgroundImage, cs.GetWebResourceUrl(rsType, "admin.pr_bgDkGray_1x30.gif").ToString) .Style.Add(HtmlTextWriterStyle.FontWeight, "normal") .Style.Add(HtmlTextWriterStyle.TextAlign, "center") .VerticalAlign = VerticalAlign.Middle End With tr.Controls.Add(td) Dim lbl_CopyRight As Label lbl_CopyRight = New Label With lbl_CopyRight .Text = "Copyright (2005-2009)" End With td.Controls.Add(lbl_CopyRight) table.RenderControl(writer) End Sub <Bindable(True)> _ <Category("Appearance")> _ <DefaultValue("")> _ <Localizable(True)> Property CssStyle_Text() As String Get Dim s As String = CStr(ViewState("CssStyle_Text")) If s Is Nothing Then Return String.Empty Else Return s End If End Get Set(ByVal Value As String) ViewState("CssStyle_Text") = Value End Set End Property End Class
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, November 13, 2009 12:44 PM
All replies
-
User-16411453 posted
It's not the anwser, but just some theory, food for thought. I don't have an anwser, not sure what your up to.
The headerTemplateContainer exist, so it's not nothing. If there is no error in intellitype, it exist
headerTemplateContainer = New CollapsingPanelTemplateContainer
Adding the control adds the child control to the parent control above it.
headerPanel.Controls.Add(headerTemplateContainer)
It doesn't make sense to me why you would check it's existence. just make it, and make it invisable, visible = False
If you need it, turn it on, visible = true
Or just destoy it with headerpanel.controls.remove(headerTemplateContainer)
Sorry to be so vague
Friday, November 13, 2009 1:05 AM -
User1982991741 posted
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
Friday, November 13, 2009 4:08 AM -
User1982991741 posted
I've overriden SaveViewState and LoadViewState in my control and placed breakpoints in each. Neither breakpoints are being hit when the control is a child control in my collapsing panel. If I run the control in my sandbox, the saveviewstate breakpoint is fired.
If I can't get this panel working, the alternative is not going to be pretty.
Thanks for your time.
Friday, November 13, 2009 8:06 AM -
User-16411453 posted
Protected Overrides Sub OnInit(ByVal e As System.EventArgs) MyBase.OnInit(e) Controls.Clear() Dim cs As ClientScriptManager = Me.Page.ClientScript Dim rsType As Type = Me.GetType() Dim Comment As LiteralControl Comment = New LiteralControl Comment.Text = "<!-- PageFooter Control V1.4.2 for ASP.NET -->" & vbCrLf Controls.Add(Comment) Dim UpdatePanel As UpdatePanel UpdatePanel = New UpdatePanel With UpdatePanel End With Controls.Add(UpdatePanel) Dim anchor As LiteralControl anchor = New LiteralControl With anchor .text = String.Format("<a name='{0}_anchor'></a>", ID)) End With UpdatePanel.ContentTemplateContainer.Controls.Add(anchor) End Sub
Here is some sample control code I gave out yesterday. Follow a similar format and it will retain the viewstate
Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Text Imports System.Web Imports System.Web.UI Imports System.Web.UI.WebControls <DefaultProperty("Text"), ToolboxData("<{0}:Display_PageFooter runat=server></{0}:Display_PageFooter>")> _ Public Class Display_PageFooter Inherits WebControl Protected Overrides Sub Render(ByVal writer As HtmlTextWriter) If Not Me.Context Is Nothing Then RenderContents(writer) Else RenderDesignMode(writer) End If End Sub Protected Overrides Sub OnInit(ByVal e As System.EventArgs) MyBase.OnInit(e) Controls.Clear() Dim cs As ClientScriptManager = Me.Page.ClientScript Dim rsType As Type = Me.GetType() Dim Comment As LiteralControl Comment = New LiteralControl Comment.Text = "<!-- PageFooter Control V1.4.2 for ASP.NET -->" & vbCrLf Controls.Add(Comment) Dim table As Table table = New Table With table .CellPadding = 0 .CellSpacing = 0 .Width = 960 .Style.Add(HtmlTextWriterStyle.Width, "960px") End With Controls.Add(table) Dim tr As TableRow tr = New TableRow With tr End With table.Controls.Add(tr) Dim td As TableCell td = New TableCell With td .Height = 30 .Style.Add(HtmlTextWriterStyle.Height, "30px") .Style.Add(HtmlTextWriterStyle.FontFamily, "Tahoma, Verdana, Arial, Helvetica, sans-serif") .Style.Add(HtmlTextWriterStyle.FontSize, "12px") .Style.Add(HtmlTextWriterStyle.Color, "#000000") .Style.Add(HtmlTextWriterStyle.BackgroundImage, cs.GetWebResourceUrl(rsType, "admin.pr_bgDkGray_1x30.gif").ToString) .Style.Add(HtmlTextWriterStyle.FontWeight, "normal") .Style.Add(HtmlTextWriterStyle.TextAlign, "center") .VerticalAlign = VerticalAlign.Middle End With tr.Controls.Add(td) Dim lbl_CopyRight As Label lbl_CopyRight = New Label With lbl_CopyRight .Text = "Copyright (2005-2009)" End With td.Controls.Add(lbl_CopyRight) End Sub Private Sub RenderDesignMode(ByVal writer As HtmlTextWriter) Controls.Clear() Dim cs As ClientScriptManager = Me.Page.ClientScript Dim rsType As Type = Me.GetType() Dim Comment As LiteralControl Comment = New LiteralControl Comment.Text = "<!--PageFooter Control V1.4.2 for ASP.NET -->" & vbCrLf Controls.Add(Comment) Dim table As Table table = New Table With table .CellPadding = 0 .CellSpacing = 0 .Width = 960 .Style.Add(HtmlTextWriterStyle.Width, "960px") End With Controls.Add(table) Dim tr As TableRow tr = New TableRow With tr End With table.Controls.Add(tr) Dim td As TableCell td = New TableCell With td .Height = 30 .Style.Add(HtmlTextWriterStyle.Height, "30px") .Style.Add(HtmlTextWriterStyle.FontFamily, "Tahoma, Verdana, Arial, Helvetica, sans-serif") .Style.Add(HtmlTextWriterStyle.FontSize, "12px") .Style.Add(HtmlTextWriterStyle.Color, "#000000") .Style.Add(HtmlTextWriterStyle.BackgroundImage, cs.GetWebResourceUrl(rsType, "admin.pr_bgDkGray_1x30.gif").ToString) .Style.Add(HtmlTextWriterStyle.FontWeight, "normal") .Style.Add(HtmlTextWriterStyle.TextAlign, "center") .VerticalAlign = VerticalAlign.Middle End With tr.Controls.Add(td) Dim lbl_CopyRight As Label lbl_CopyRight = New Label With lbl_CopyRight .Text = "Copyright (2005-2009)" End With td.Controls.Add(lbl_CopyRight) table.RenderControl(writer) End Sub <Bindable(True)> _ <Category("Appearance")> _ <DefaultValue("")> _ <Localizable(True)> Property CssStyle_Text() As String Get Dim s As String = CStr(ViewState("CssStyle_Text")) If s Is Nothing Then Return String.Empty Else Return s End If End Get Set(ByVal Value As String) ViewState("CssStyle_Text") = Value End Set End Property End Class
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, November 13, 2009 12:44 PM -
User1982991741 posted
Thanks for the example. It is really appreciated.
It turns out that my code is quite similar in how it creates the controls. I found the problem.... Somebody had put a panel around the content area on the masterpage with viewstateenabled = false....
All fixed now. Thanks for the help
Saturday, November 14, 2009 6:27 AM -
User-16411453 posted
Don't forget to mark it as solved
Saturday, November 14, 2009 2:01 PM