J
Joshua Gunder via .NET 247
This is my first attempt at building my own compiled customcontrol. I have a custom control that contains a textbox and alistbox.
In a given aspx.vb class I will instantiate my custom control andbind its listbox to a datareader, (If Not PostBack). The custom
control loads on the page with my textbox and listbox below itand everything is fine. However if I add a submit button the
containing page and click it, the list comes back empty the nexttime. Why isn't viewstate for child controls in a custom controlmaintained? How do I accomplish this? Below is my code for thecustom control. Note: I didnt' know of a good way to access the
textbox and listbox so I created "Get..." functions that returnreferences to these webControls. ANy help would be appreciated,thanks.
BTW, I tried posting this message before, but I couldn't find itin the list. While full of information, this site is
horribly painful to navigate you can never figure out where youare, 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 AsSystem.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
In a given aspx.vb class I will instantiate my custom control andbind its listbox to a datareader, (If Not PostBack). The custom
control loads on the page with my textbox and listbox below itand everything is fine. However if I add a submit button the
containing page and click it, the list comes back empty the nexttime. Why isn't viewstate for child controls in a custom controlmaintained? How do I accomplish this? Below is my code for thecustom control. Note: I didnt' know of a good way to access the
textbox and listbox so I created "Get..." functions that returnreferences to these webControls. ANy help would be appreciated,thanks.
BTW, I tried posting this message before, but I couldn't find itin the list. While full of information, this site is
horribly painful to navigate you can never figure out where youare, 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 AsSystem.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