Hi,
1) Implement INamingContainer interface in your control
2) Create instances of child controls in overridden CreateChildControls
method and add them to the Controls collection of your control. This way
child controls participate in the control lifecycle and will also keep their
state.
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke [quoted text, click to view] "Joshua Gunder via .NET 247" <anonymous@dotnet247.com> wrote in message
news:%23TMD6tQOEHA.204@TK2MSFTNGP10.phx.gbl...
This is my first attempt at building my own compiled custom control. I have
a custom control that contains a textbox and a listbox.
In a given aspx.vb class I will instantiate my custom control and bind its
listbox to a datareader, (If Not PostBack). The custom
control loads on the page with my textbox and listbox below it and
everything is fine. However if I add a submit button the
containing page and click it, the list comes back empty the next time. Why
isn't viewstate for child controls in a custom control maintained? How do I
accomplish this? Below is my code for the custom control. Note: I didnt'
know of a good way to access the
textbox and listbox so I created "Get..." functions that return references
to these webControls. ANy help would be appreciated, thanks.
BTW, I tried posting this message before, but I couldn't find it in the
list. While full of information, this site is
horribly painful to navigate you can never figure out where you are, or why
some topics are different colors, etc. Its like a
circus in here with no explanation as to how the site works.
----------------------
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Class FilterList : Inherits WebControl
Private _txtFilter As New TextBox
Private _lstItems As New ListBox
Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
_txtFilter.ID = "txtFilterBox"
_txtFilter.Width = Me.Width
_lstItems.ID = "lstItems"
_lstItems.Width = Me.Width
_lstItems.Height = Me.Height
_txtFilter.Attributes.Add("onkeyup", "LoadNearest('" & _txtFilter.ID
& "', '" & _lstItems.ID & "');")
output.Write(GenerateClientScript)
output.Write("<table cellpadding=""0"" cellspacing=""0""
border=""0"">" & vbCrLf & _
"<tr><td>" & vbCrLf)
_txtFilter.RenderControl(output)
output.Write("</td></tr><tr><td>")
_lstItems.RenderControl(output)
output.Write("</td></tr></table>")
End Sub
Public Function GetTextBox() As TextBox
Return _txtFilter
End Function
Public Function GetListBox() As ListBox
Return _lstItems
End Function
End Class
----------------------
--------------------------------
From: Joshua Gunder
-----------------------
Posted by a user from .NET 247 (
http://www.dotnet247.com/)
<Id>97+4V033dk2M4ec/5utMew==</Id>