[quoted text, click to view] >"Micke Palm" <micke@ripoff.nykoping.net> wrote in message
news:OpKaAPcXEHA.3668@TK2MSFTNGP09.phx.gbl...
>Hi!
>
>I want to use a parent page and load webusercontrols to this page
dynamically. The problem I got is how I can set a label.text in parent page
from a usercontrol.
[quoted text, click to view] >
>A scenenario is if I have a button into the usercontrol and want to set a
text to a label in the parents page. I've set the click_sub to public and
the label to friend so I can se it, but when I try to dedicate a >text I got
this error.
[quoted text, click to view] >Object reference not set to an instance of an object.
>
>My declaration is ...
>Dim test As New myParentClass
>test.ChangedBy.Text = "Ett test"
Use:
Dim test As myParentClass = CType(Page,myParentClass)
test.ChangedBy.Text = "Ett test"
By the way, I believe that your problem indicates a flaw in your design.
According to the object oriented philosophy, a user control is
supposed to stand on its own. It shouldn't need to access external
controls, nor should it assume that its parent is of a certain class.
You could consider making the label a part of the user control,
except if you want to add multiple user controls and a single label
to your page. In that case, you could consider adding an event
to the user control, adding an event handler to the page, and
setting the label's text there.
Jos