dynamic userControl can't be accessed during page load

A

Allan

I have a userControl that I create based on how many rows I retrieve in a
dataset. I add the control to my page but can't access it during the
page_load. I assume this is due to the control not being actually created
yet, the code is as follows...
For Each row In dt.Rows
Dim travelRowCtrl As New TravelContainer
Me.plcHlderTravelTime.Controls.Add(travelRowCtrl)
travelRowCtrl.loadData(row) 'call to load the data
Next
the loadData call is a public function in the travelRowCtrl it attempts to
access some items in the user control. The code is as follows...
Public Function loadData(ByVal drDataRow As DataRow) As Boolean
cmbMode.SelectedIndex = CType(drDataRow.Item("expense_cd"), Integer)
txtDepartDate.Text = CType(drDataRow.Item("departure_dt"), String)
txtDepartTime.Text = CType(drDataRow.Item("departure_time"), String)
End Function
the result is a system exception "Object reference not set to an instance of
an object. "
QUESTION: Is there away to access this control during page_load? If so how
should I do it.
 
J

jsh02_nova

Allan,
Try
Public Function loadData(ByRef drDataRow As DataRow) As Boolean
cmbMode.SelectedIndex = CType(drDataRow.Item("expense_cd"),
Integer)
txtDepartDate.Text = CType(drDataRow.Item("departure_dt"), String)
txtDepartTime.Text = CType(drDataRow.Item("departure_time"), String)
End Function

thx
-jsh
 
J

Jonathan V

I'm not quite sure what your DataRow is from in terms of control. You can
usually get a reference from the appropriate call to findControl(NameStr).
You may want to use Trace to find what the control tree looks like, or put a
line of code to find out what the control that has been added has a
ClientID. ( I use a call to the Windows Event )
Regards Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top