Manipulating a User Control from another User Control

T

Tom Rowton

This one has me a bit confused and I'm not finding what I
need in the MSDN or by searching these forums, so here
goes...


I have a rather large, complex code-in-page WebForm
(don't ask) and a section of that Form is 4 or 5
ASP:panels pretending to be a set of Tabs, each with its
own section of the form.

In order to simplify managing this page, since code-
behind is not an option (don't ask, not my fault), I
thought I had the solution...

I would convert each Panel into a User Control.
The problem is that the panels usually depend on at least
one Form Control from at least one other Panel.

I already know about RaiseBubbleEvent() and OnBubbleEvent
() and have used them elsewhere, but they only work going
UP the container heirarchy.

I need to :
1 - (partially) handle an event in the UserControls
(panels), then (partially handle the same event in
ANOTHER UserControl(panel) on the same form/page.

2 - handle an event in a UserControl(panel) BUT be able
to retrieve values from form fields(Controls) in OTHER
UserControls(panels) to help determine how to handle the
event.

3 - (partially) handle an event in the Form(aspx)
depending on values of form controls in the UserControls

4 - manipulate values of form controls in the
UserControls


Like I said, I already know how to Bubble events, but
that only goes up.
The part I am missing is how to "Elbbub" events (bubble,
backwards) or manipulate data in child objects.

The trick is, this is all Code-in-Page and nothing will
convince those in control to return to Code Behind.

Anyone know how to do what I want/need to do?

I have a set of aspx/ascx pages that I can email or ftp
for anyone interested.
 
K

Kevin Spencer

Okay, let me see if I understand you correctly. You've got an Event Handler
for one UserControl that needs to do something with another UserControl,
right? It looks to me like your error is in using Page.FindControl(...). The
FindControl() method of a Control looks for controls in that Control's
Controls Collection (was that a confusing sentence or what?). Your
UserControls are not in the Page's Controls Collection; they are in your
Form's Controls collection. Does that help?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.
 
T

Tom Rowton

Form's Controls collection. Does that help?
It's good info to have, but doesn't really fix my
problem.

in MyCaseSub.ascx where I have commented out
---------------------------------------------
Dim MyControl as Control =
Page.FindControl("MainPanel1")
if (not MyControl is Nothing) then
lblParent.Text =
MyControl.MainLabelValue()
else
lblParent.Text = "MainPanel1 not
found"
end if
------------------------------------------------

The "else" never happens.
MyControl is _never_ Nothing.
I can print the ID out just fine.
But I am unable to access the "MainLabelValue()" Property
GET - which works just fine from the bubbled event in
MyCase.aspx.

To sum up, I know that Page.FindControl() finds the
usercontrol, because I can print out the ID I've given it
in the HTML, but I cannot access the Property I've given
in the script block of the UserControl.

Or did I just misunderstand your point?
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top