I'm no expert in the subject, but I don't know of a way to get two user
controls to talk to each other directly.
One way to empower communication is indirectly through the parent page. For
example, you may have two user controls on a page, uc1 and uc2. If uc1 has
an error, have it create and event which will be received by the parent and
acted on by an event handler in the parent. The parent will have a direct
reference to uc2, so you can then set properties or do whatever you want
with uc2 in the event handler.
Also, your code snippet looks like you are trying to dynamically create an
instance of a user control. I've always done this using the loadcontrol
call, for example
Dim questionDisplayCtrl As Control =
LoadControl("../templates/questionListItemOptions.ascx")
What you are trying to do (Dim ctrlError as new ucErrors) looks more
suitable for a regular web server control, class, or a composite control.
"eagle" <ea***@yahoo.com> wrote in message
news:eZ**************@TK2MSFTNGP15.phx.gbl...
How do I access a control, like a placeholder, from another page, or
another user control that may be on the same page.
For instance, I have a web page with 2 user controls. One user controls
contains a placeholder to that will contain any error messages to be
displayed. If the first user control creates an error, I want to be able
to push that error to the 2nd control to display it at the placeholder.
I have tried
Dim ctrlError as new ucErrors
Dim lbl as new label
lbl.text = "Error has occurred"
ctrlError.ph.Controls.Add(lbl)
But I get an error saying "System.NullReferenceException: Object reference
not set to an instance of an object."