This is a migrated thread and some comments may be shown as answers.

Why do your controls "hide" other controls contained within them?

3 Answers 60 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Brent
Top achievements
Rank 1
Brent asked on 26 Sep 2008, 02:19 PM
I am trying to raise and handle events, between ASP.NET user controls (ascx) files.

So basically, I have an aspx page that contains two ascx user controls.
I raise an event from one of them, and handle the event in the other.

To make it very simple to code this, I've exposed (declared) each user control as public, in the code behind of the aspx page.  Again, that makes it easy to do code all of this without having to do FindControl to get the controls.

In my main page for instance, I would have:

        public UCQueueItem ucQueueItem;
        public UCFiling ucFiling;

Each of these are user controls.  I can then raise an event in one, and handle it in the other if I simple "wire" the event up from the main page, like so:

this.ucFiling.FilingChangedEvent += new FilingDetailsChangedEventHandler(ucQueueItem.Update_OnFilingDetailsChanged);

That all works well and good, UNTIL I use a RadPanelBar and include my ucQueueItem user controls within the panel bar.  Since it then becomes a child of your control, I can no longer use the above syntax to wire up the event.  THIS STINKS.  I then have to do whacky "FindControl" stuff...

This type of behavior happens with all of your controls (like the grid, if you put items within Templates in the grid as well).

WHY WHY WHY, cannot I not access my publicly exposed controls, when they are nested within your controls?
Brent

3 Answers, 1 is accepted

Sort by
0
Brent
Top achievements
Rank 1
answered on 26 Sep 2008, 02:50 PM
Just to give you an example of what I'm talking about and what is frustrating.  Before I put the user control inside of the RadPanelBar, I can do this one line of clean code to wire up a method:

ucFiling.FilingChangedEvent += new FilingDetailsChangedEventHandler(ucQueueItem.Update_OnFilingDetailsChanged);

After I place the QueueItem user control in the RadPanelBar, and then expose the panelbar publicly (in code behind), I then have to do the ugly FindControl and use casting:

UCCQueueItem ucQID = (UCCQueueItem)UCCSummaryPanelBar.Items[0].FindControl("ucUCCQueueItem");
ucFiling.FilingDetailsChangedEvent += new FilingDetailsChangedEventHandler(ucQID.Update_OnFilingDetailsChanged);

So again my question is "How can I, if at all, expose my user control that is contained in the RadPanelBar, so that I can access things that are publicly exposed on it?".

0
Serrin
Top achievements
Rank 1
answered on 26 Sep 2008, 07:54 PM
Hey Brent,

It kinda makes sense, since the controls would now be contained within the Panel, you have to access them via the Panel.  So it still needs to go through the panel since it's holding onto the control for you...  You know, kinda like your wife can grab and use your debit card whenever she wants, but she has to locate it in your wallet before she can access it. :)

Not sure if there is a way to pre-assign them like you do with the Public statements in your first post, but at least it's only a one-line workaround that gives you access.
0
Brent
Top achievements
Rank 1
answered on 26 Sep 2008, 07:59 PM
I understand that they are children of the container.  What doesn't make sense, is how you cannot access them programmatically unless you rely on 'FindControl'.

Just because a child is contained by something else, shouldn't mean that it makes sense that you'd have to access it using Find Control.  I can publicly expose .net controls that reside within in a user control...

It's the ugliness of the one line workaround that I don't like.  What if my item is no longer the first item in the collection?  I'd have to write more code to check for this...  That's what I'm bummed about.  It shouldn't be that way.
Tags
PanelBar
Asked by
Brent
Top achievements
Rank 1
Answers by
Brent
Top achievements
Rank 1
Serrin
Top achievements
Rank 1
Share this question
or