Dynamically added user control throws object not set

A

andyrich_1

HI,

I'm adding a usercontrol to a webform in the following way


Dim ctlRate As New ctlRatesTable
ctlRate.SomeMethod()
Me.Page.Controls.Add(ctlRate)

Where sub routine "SomeMethod" attempts to set the text property of a
lable webcontrol. The problem is that the lable hasn't been created.
I've tried calling EnsureChildControls() before using the lable control
but this hasn't helped.

Any ideas what I'm doing wrong?

Thanks,
Andy
 
T

Teemu Keiski

Try putting it also like this:

***
Dim ctlRate As New ctlRatesTable

' FOLLOWING TWO LINES IN DIFFERENT ORDER THAN ORIGINALLY
Me.Page.Controls.Add(ctlRate)
ctlRate.SomeMethod()

And yes, inside ctlRatesTable, before accessing child controls make sure
EnsureChildControls is called (and child controls instantiated in
CreateChildControls method)
 

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,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top