Nested Controls not visible to Page?

L

lisa

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
 
L

lisa

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
 
S

samuelrobertson

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.
 
L

lisa

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.

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
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top