siri Posted May 8, 2008 Share Posted May 8, 2008 i am creating a custom template control. But the problem is that I am not able to maintain the viewstate of the custom template control.How do i maintain the viewstate of the template items.Here is the code snippet:**********************************************Imports SystemImports System.WebImports System.Web.UINamespace myControlsPublic Class TemplateItemInherits ControlImplements INamingContainer Private _dataItem As String Public Sub New( DataItem As String ) _dataItem = DataItem End Sub Public Property DataItem As String Get Return _dataItem End Get Set _dataItem = Value End Set End PropertyEnd Class<ParseChildren(true)> Public Class SimpleTemplateInherits ControlImplements INamingContainer Private _itemTemplate As ITemplate Private _text As String Public Property Text As String Get Return _text End Get Set _text = Value End Set End Property <TemplateContainer(GetType(TemplateItem))> _ Public Property ItemTemplate As ITemplate Get Return _itemTemplate End Get Set _itemTemplate = Value End Set End Property Public Overrides Sub DataBind() EnsureChildControls() MyBase.DataBind() End Sub Protected Overrides Sub CreateChildControls() Dim objTemplateItem As TemplateItem Controls.Clear() objTemplateItem = New TemplateItem( Me.Text ) ItemTemplate.InstantiateIn( objTemplateItem ) Controls.Add( objTemplateItem ) End SubEnd ClassEnd Namespace******************************************************** Link to comment Share on other sites More sharing options...
aspnetguy Posted May 8, 2008 Share Posted May 8, 2008 Anything you want to persist you can store in the ViewState collection the same way you would store an object in Session. Link to comment Share on other sites More sharing options...
jesh Posted May 8, 2008 Share Posted May 8, 2008 For example: ViewState["MyData"] = "Some data"; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.