G
Guest
I have created a Custom Control that accepts an array of Objects and uses the
contents of those objects to add controls to its child control struture and
have them rendered to the display. I also add this array of objects to view
state and regenerate the objects on postback using the
System.Activator.CreateInstance Method. This all seems to work fine but the
viewstate of my dyanically recreated objects is not being restored. What to I
need to do to make this happen? (See Code Below)
Thanks
Earl
Imports System.ComponentModel
Imports System.Web.UI
<Serializable(), DefaultProperty("Text"), ToolboxData("<{0}:TabMenu
runat=server></{0}:TabMenu>")> Public Class TabMenuA
Inherits System.Web.UI.WebControls.WebControl
<Bindable(True), Category("Data"), DefaultValue("")> Public Property
TabMenuItems() As TabMenuItem()
Get
Dim x As Object = ViewState("TabMenuItems")
Return IIf(x Is Nothing, Nothing, CType(x, TabMenuItem()))
End Get
Set(ByVal Value As TabMenuItem())
ViewState("TabMenuItems") = Value
End Set
End Property
'Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
'End Sub
<Serializable()> _
Class TabMenuItem
Private _Row As Int32
Private _Order As Int32
Private _Value As String
<NonSerialized()> Private _RenderControl As
System.Web.UI.WebControls.WebControl
Private _ControlType As System.Type
Private _ControlId As String
Property Row() As Int32
Get
Return _Row
End Get
Set(ByVal Value As Int32)
_Row = Value
End Set
End Property
Property Order() As Int32
Get
Return _Order
End Get
Set(ByVal Value As Int32)
_Order = Value
End Set
End Property
Property Value() As String
Get
Return _Value
End Get
Set(ByVal Value As String)
_Value = Value
End Set
End Property
<System.Xml.Serialization.XmlIgnore()> _
Property RenderControl() As System.Web.UI.WebControls.WebControl
Get
If Not _RenderControl Is Nothing Then
Return _RenderControl
Else
_RenderControl =
System.Activator.CreateInstance(ControlType)
_RenderControl.ID = ControlId
Return _RenderControl
End If
End Get
Set(ByVal Value As System.Web.UI.WebControls.WebControl)
_RenderControl = Value
ControlType = Value.GetType
ControlId = Value.ID
End Set
End Property
Private Property ControlType() As System.Type
Get
Return _ControlType
End Get
Set(ByVal Value As System.Type)
_ControlType = Value
End Set
End Property
Private Property ControlId() As String
Get
Return _ControlId
End Get
Set(ByVal Value As String)
_ControlId = Value
End Set
End Property
End Class
Protected Overrides Sub CreateChildControls()
If Not Page.IsPostBack Then
If Not TabMenuItems Is Nothing Then
If TabMenuItems.Length > 0 Then
For Each MenuItem As TabMenuItem In TabMenuItems
If Not MenuItem Is Nothing Then
Me.Controls.Add(MenuItem.RenderControl)
End If
Next
End If
End If
End If
End Sub
End Class
contents of those objects to add controls to its child control struture and
have them rendered to the display. I also add this array of objects to view
state and regenerate the objects on postback using the
System.Activator.CreateInstance Method. This all seems to work fine but the
viewstate of my dyanically recreated objects is not being restored. What to I
need to do to make this happen? (See Code Below)
Thanks
Earl
Imports System.ComponentModel
Imports System.Web.UI
<Serializable(), DefaultProperty("Text"), ToolboxData("<{0}:TabMenu
runat=server></{0}:TabMenu>")> Public Class TabMenuA
Inherits System.Web.UI.WebControls.WebControl
<Bindable(True), Category("Data"), DefaultValue("")> Public Property
TabMenuItems() As TabMenuItem()
Get
Dim x As Object = ViewState("TabMenuItems")
Return IIf(x Is Nothing, Nothing, CType(x, TabMenuItem()))
End Get
Set(ByVal Value As TabMenuItem())
ViewState("TabMenuItems") = Value
End Set
End Property
'Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
'End Sub
<Serializable()> _
Class TabMenuItem
Private _Row As Int32
Private _Order As Int32
Private _Value As String
<NonSerialized()> Private _RenderControl As
System.Web.UI.WebControls.WebControl
Private _ControlType As System.Type
Private _ControlId As String
Property Row() As Int32
Get
Return _Row
End Get
Set(ByVal Value As Int32)
_Row = Value
End Set
End Property
Property Order() As Int32
Get
Return _Order
End Get
Set(ByVal Value As Int32)
_Order = Value
End Set
End Property
Property Value() As String
Get
Return _Value
End Get
Set(ByVal Value As String)
_Value = Value
End Set
End Property
<System.Xml.Serialization.XmlIgnore()> _
Property RenderControl() As System.Web.UI.WebControls.WebControl
Get
If Not _RenderControl Is Nothing Then
Return _RenderControl
Else
_RenderControl =
System.Activator.CreateInstance(ControlType)
_RenderControl.ID = ControlId
Return _RenderControl
End If
End Get
Set(ByVal Value As System.Web.UI.WebControls.WebControl)
_RenderControl = Value
ControlType = Value.GetType
ControlId = Value.ID
End Set
End Property
Private Property ControlType() As System.Type
Get
Return _ControlType
End Get
Set(ByVal Value As System.Type)
_ControlType = Value
End Set
End Property
Private Property ControlId() As String
Get
Return _ControlId
End Get
Set(ByVal Value As String)
_ControlId = Value
End Set
End Property
End Class
Protected Overrides Sub CreateChildControls()
If Not Page.IsPostBack Then
If Not TabMenuItems Is Nothing Then
If TabMenuItems.Length > 0 Then
For Each MenuItem As TabMenuItem In TabMenuItems
If Not MenuItem Is Nothing Then
Me.Controls.Add(MenuItem.RenderControl)
End If
Next
End If
End If
End If
End Sub
End Class