How to Change hierarchy of controls?

N

Nenad Prekupec

Hi,
I'm writing custom control inherited from system.web.ui.webcontrols.panel. I
want that MyPanel make some modifications in rendering panel with its child
controls and add some button to render (and raise events) on that panel. I
have created control and it works fine BUT....

After post back of aspx page, all child controls on MyPanel are losing
entered data. It's not the metter of post back data binding!
It's the metter of Moving Child controls from Controls collection of base
class to Controls collection of Cell control. In this proccess of moving
texboxes (and other MyPanel child controls) loose properties.
MyPanel implements INamingContainer. If I remove this implementation (class
without INamingConatiner) on MyPanel, control renders the way I want , but
then Events are not working; and if I put INamingContainer back, rendering
of child controls values is not working.
Does anybody know how to do this?


Now my idea was to create Table class hierarchy in CreateChildControls()
method like this:

Protected Overrides Sub CreateChildControls()
mybase.CreateChildControls() ' I concluded that Controls
collection at this point is full of controls that were Drag&droped on
MyPanel at design-time


Dim mainTable1 As New Table
Dim mainRow1 As New TableRow
Dim mainCell1 As New TableCell

While (Me.Controls.Count <> 0)
mainCell1.Controls.Add(Controls(0))
End While
...
... lines of code adding cells in rows, rows in table
...
Dim btnOk As New Button
btnOk.Text = "Ok"
AddHandler btnOk.Click, AddressOf ButtonOkClick
..
... adding button in table cell control collection
..
End Sub



P.S. VS2003, VB.NET framework ver 1.1
 
J

John Saunders

Nenad Prekupec said:
Hi,
I'm writing custom control inherited from system.web.ui.webcontrols.panel. I
want that MyPanel make some modifications in rendering panel with its child
controls and add some button to render (and raise events) on that panel. I
have created control and it works fine BUT....

After post back of aspx page, all child controls on MyPanel are losing
entered data. It's not the metter of post back data binding!
It's the metter of Moving Child controls from Controls collection of base
class to Controls collection of Cell control. In this proccess of moving
texboxes (and other MyPanel child controls) loose properties.
MyPanel implements INamingContainer. If I remove this implementation (class
without INamingConatiner) on MyPanel, control renders the way I want , but
then Events are not working; and if I put INamingContainer back, rendering
of child controls values is not working.
Does anybody know how to do this?


Now my idea was to create Table class hierarchy in CreateChildControls()
method like this:

You can't change the control hierarchy and keep values. The hierarchy is
what defines wihch values belong to which controls!

I think you have the right idea to put the controls where you want them in
the first place!
 
N

Nenad Prekupec

Yes John I thought that also, but it seems that I cant do that :)
Do you have idea how could I make this hierarchy without moving controls in
collections?
+--------------MyPanel----------------------------+
++------------------------------------------------++
+ | Controls on MyPanel | +
+ | added in designer by Drag&Drop| +
++------------------------------------------------++
+---------------------------------------------------+
 
N

Nenad Prekupec

I should mention that table acting container is dynamicly constructed in
CreateChildControls method and put inside Controls collection.
 
N

Nenad Prekupec

I have managed to trick the way child controls are added to
controlCollection in this way:
1) declared private

Private _innerContainer As Control

2) overrided AddParsedSubObject
Protected Overrides Sub AddParsedSubObject(ByVal obj As Object)
EnsureChildControls()
If (Not IsNothing(obj)) Then
_innerContainer.Controls.Add(obj)
End If
End Sub


that way CreateChildControls method is invoked before parsing child controls

3) in CreateChildControls method I'm saving reference to cell where I'm
adding all child controls the way they are drag&droped on MyPanel

in Design-time of aspx

4) as you can see in step 2, after creation of Controls collection in
CreateChildControls method I'm adding parsed controls to target cell control
collection

_innerContainer.controls.add(obj)



And this works (at least for now :))

If anybody knows something better please, give your advice.

Thanks John!
 

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,997
Messages
2,570,239
Members
46,828
Latest member
LauraCastr

Latest Threads

Top