all groups > asp.net building controls > may 2005 >
You're in the

asp.net building controls

group:

Nested Controls not visible to Page?


Nested Controls not visible to Page? lisa NO[at]SPAM starways.net
5/4/2005 8:17:16 AM
asp.net building controls: I'm still banging away at my tabstrip problem, which I've mentioned in
other threads here.

One of the things I've noticed is that in design view, none of the
controls inside of a tab page show up in the property grid.

This makes sense, I suppose, because once they're added, even if
they're being added manually in the HTML view, they're a part of the
control, and they aren't any more visible to the page than any other
constituent of the control.

That's probably why postback data isn't updating those controls. I
still don't see how Microsoft beat that in their Multipage control, but
apparently they did. Which means that it's possible.

One thing I tried was this:

============================
' Populate controls with PostData, saving a list of those that were
modified:
Dim modifiedControls As New ArrayList
Dim myControl As control
For Each key As String In Page.Request.Form.AllKeys
myControl = FindControl(key)
If TypeOf myControl Is IPostBackDataHandler Then
If CType(myControl, IPostBackDataHandler).LoadPostData(key,
Page.Request.Form) Then
modifiedControls.Add(myControl)
End If
End If
Next key

'Raise PostDataChanged event on all modified controls:
Dim control As IPostBackDataHandler
For Each control In modifiedControls
control.RaisePostDataChangedEvent()
Next control
============================

I stole that from
http://www.codeproject.com/aspnet/PersistentStatePage.asp, with some
modifications.

The problem is, FindControl doesn't find the controls. I tried
modifying it so that it does FindControl on each Tab control in the
TabStrip's TabCollection. Still nothing.

Here's something twisted from the Command Window:

?Tabs(2).Controls(1).ID
"CheckBox1"
?Tabs(2).HasControls
True
?CType(Tabs(2),Control).FindControl("Checkbox1").ID
Referenced object 'FindControl' has a value of 'Nothing'.
?CType(Tabs(2),Control).Controls(1).ID
"CheckBox1"

Can anyone explain this to me? Just those last two items make no sense
at all. CheckBox1 is visible when I try to get its ID. But when I try
from the other direction, using FindControl to get the control using
the ID, I get Nothing.

Thanks,
Lisa
Re: Nested Controls not visible to Page? lisa NO[at]SPAM starways.net
5/4/2005 10:43:46 AM
Well, I solved it. It's ugly, but it works. I added a hidden dropdown
to my tabstrip control, and I added an onpropertychanged event to each
contained control as I add them to the render. That event triggers a
vbscript function that adds the name of the changed control to the
hidden dropdown (if it isn't already there), and on postback, I check
that field and update anything listed in it.

And as far as I can tell, the bloody nasty thing is working beautifully
now. And I can finally stop thinking about it and just use it! Yay!

Lisa

[quoted text, click to view]
Re: Nested Controls not visible to Page? samuelrobertson NO[at]SPAM gmail.com
5/5/2005 10:56:50 AM
I didn't read enough of this post to find this out, but did you know
that FindControl() only works 1 level deep? If this isn't true then
someone please correct me.
Re: Nested Controls not visible to Page? lisa NO[at]SPAM starways.net
5/5/2005 11:16:18 AM

[quoted text, click to view]

You're right, but if you look at what I posted, I was actually looping
through the children and doing FindControl on each of them in turn.

FindChildren only looks at immediate children. Not children of
children.

Lisa
AddThis Social Bookmark Button