Trying to place a ListControl in page_init
Posted on 2006-07-07
Within my page I have a list. In some cases this displays as a radiobuttonlist, and in other case as a checkboxlist.
This list is populated and read back by other subroutines. From various tutorials it seems that dynamic controls must be generated in page_init if they are to be available across postbacks.
Given the following code, how do I add this listcontrol to the page in order for other subs to cast it as either of the 2 correct list types?
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
Dim lc As ListControl
lc.ID = "lc"
Sub rePopulate(ByVal aNumber As Boolean) ' called later in the page
Dim answers As ListControl = CType(ph.FindControl("lc"), ListControl)
If aNumber Then
answers = New RadioButtonList
answers = New CheckBoxList
..... ' populate list items ....
The page_init is giving an error:
Value cannot be null.
Parameter name: child