Reputation: 883
I know how to do it in win forms, but how do i position a dynamically added control on top of another dynamically added control code behind?
I tried doing: panelNew.ApplyStyle(panelOld.ControlStyle);
where panelNew and panelOld are Panels and I am trying to position panelNew on top of panelOld but it did not do anything. (Both panels are exactly same size)
Thanks.
Upvotes: 1
Views: 696
Reputation: 498
If you want to do it purely in code-behind, try something like this:
panelNew.Style[HtmlTextWriterStyle.Position] = 'absolute';
panelNew.Style[HtmlTextWriterStyle.ZIndex] = '999';
The zindex of the panel you want on the top will have to be greater than the other panel.
Upvotes: 1
Reputation: 67898
To do this you would likely want to leverage absolute
positioning. Think about it like this, it's all about the styling. Consider the following style:
#pnl1 {
position: absolute;
left: 10px;
top: 10px;
z-index: 1000;
}
#pnl2 {
position: absolute;
left: 10px;
top: 10px;
z-index: 1001;
}
#pnl2
is now directly above #pnl1
.
Upvotes: 0