Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Dynamically added user control throws object not set

Reply
Thread Tools

Dynamically added user control throws object not set

 
 
andyrich_1@hotmail.com
Guest
Posts: n/a
 
      01-03-2006
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

 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      01-03-2006
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)


--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> HI,
>
> I'm adding a usercontrol to a webform in the following way
>
>
> > > >

> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reference web control in dynamically added user control, ASP.NET 2 =?Utf-8?B?U2FtdWVs?= ASP .Net 7 08-10-2005 02:12 AM
Dynamically loading user control into Placeholder gives Object reference not set to an instance of an object Phoenix ASP .Net Building Controls 2 06-06-2005 04:02 PM
Load User Control Dynamically, Cast object dynamically =?Utf-8?B?UmV6YSBOYWJp?= ASP .Net 1 03-05-2005 12:04 AM
how come user control added to page doesn't get added to codebehind file? Bennett Haselton ASP .Net 1 11-08-2004 09:26 PM
Dynamically Added User Control not accessible! Cathy ASP .Net Web Controls 0 12-16-2003 12:21 PM



Advertisments