Reputation: 4987
On my page, I have several controls. I need to change the order in which the controls appear on the page depending on some conditions. Is there a way to "cut & paste" a control to a different location within the aspx? I would like this to happen on the server side before the page is rendered.
This is a legacy app and the layout is table based, so doing the repositioning on the client is not desired, not to mention waiting for the page to fully load and then doing the repositioning would most likely cause the user to see the controls reposition.
Thanks, --Ed
Upvotes: 0
Views: 52
Reputation: 39807
You can use Add
method of child Controls
collection of the target control to move the source element. For example you have following table
<asp:Table ID="tbl" runat="server">
<asp:TableRow>
<asp:TableCell ID="Cell1">
<asp:Label runat="server" ID="lbl" Text="Data 1"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ID="Cell2" >
<asp:Label runat="server" ID="lbl2" Text="Data 2"></asp:Label>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
If you want to move label "lbl" from cell "Cell1" to cell "Cell2" you can do this in server-side code:
Cell2.Controls.Add(lbl)
Upvotes: 1