473,322 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

I want to change parent...

Hi!
I want to change the position of a generic control. I want to append it
to a different parent.
I try some methods but I have some problem with complex controls (like
dropdown, checkboxlist)

I wrote a simple code for testing.
If you try to check something and write in textbox, after two click you
lose only checkboxes!

WHY?

Please, help me. Thanks a lot

Roberto

---------------------------------------------------------------------------

<%@ Page Language="C#" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CheckBoxList1.Items.Add("One");
CheckBoxList1.Items.Add("Two");
CheckBoxList1.Items.Add("Three");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Panel2.Controls.Add(Panel1);
}
protected void Button3_Click(object sender, EventArgs e)
{
Panel3.Controls.Add(Panel1);
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">

<asp:Panel ID="Panel1" runat="server"
Height="50px" Width="125px"
BorderColor="#C0C000" BorderStyle="Solid">
<asp:CheckBoxList ID="CheckBoxList1" runat="server" />
<asp:TextBox ID="TextBox1" runat="server" />
</asp:Panel>

<br />
<asp:Button ID="Button2" runat="server"
OnClick="Button2_Click" Text="Button" />
<br />
<asp:Panel ID="Panel2" runat="server"
BorderColor="Red" BorderStyle="Solid"
Height="50px" Width="125px">
</asp:Panel>

<br />
<asp:Button ID="Button3" runat="server"
OnClick="Button3_Click" Text="Button" />
<br />
<asp:Panel ID="Panel3" runat="server"
BorderStyle="Solid"
Height="50px" Width="125px">
</asp:Panel>

</form>
</body>
</html>

Jun 22 '06 #1
3 1936
You can't take a panel that is part of the page and just add it
somewhere else in the page. You will end up with having two controls
that think that the panel is their child, but the panel will only think
that one of them is the parent.

If you want to move a control in the page, you have to first remove it
from the original parent's Controls collection.

Softimax wrote:
Hi!
I want to change the position of a generic control. I want to append it
to a different parent.
I try some methods but I have some problem with complex controls (like
dropdown, checkboxlist)

I wrote a simple code for testing.
If you try to check something and write in textbox, after two click you
lose only checkboxes!

WHY?

Please, help me. Thanks a lot

Roberto

---------------------------------------------------------------------------

<%@ Page Language="C#" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CheckBoxList1.Items.Add("One");
CheckBoxList1.Items.Add("Two");
CheckBoxList1.Items.Add("Three");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Panel2.Controls.Add(Panel1);
}
protected void Button3_Click(object sender, EventArgs e)
{
Panel3.Controls.Add(Panel1);
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">

<asp:Panel ID="Panel1" runat="server"
Height="50px" Width="125px"
BorderColor="#C0C000" BorderStyle="Solid">
<asp:CheckBoxList ID="CheckBoxList1" runat="server" />
<asp:TextBox ID="TextBox1" runat="server" />
</asp:Panel>

<br />
<asp:Button ID="Button2" runat="server"
OnClick="Button2_Click" Text="Button" />
<br />
<asp:Panel ID="Panel2" runat="server"
BorderColor="Red" BorderStyle="Solid"
Height="50px" Width="125px">
</asp:Panel>

<br />
<asp:Button ID="Button3" runat="server"
OnClick="Button3_Click" Text="Button" />
<br />
<asp:Panel ID="Panel3" runat="server"
BorderStyle="Solid"
Height="50px" Width="125px">
</asp:Panel>

</form>
</body>
</html>

Jun 23 '06 #2
Your solution doesn't work
I update the original code with:

protected void Button2_Click(object sender, EventArgs e)
{
Panel1.Parent.Controls.Remove(Panel1);
Panel2.Controls.Add(Panel1);
}
protected void Button3_Click(object sender, EventArgs e)
{
Panel1.Parent.Controls.Remove(Panel1);
Panel3.Controls.Add(Panel1);
}

but the result is the same.

I also try "deep clone" of the panel, but I have only tons of errors

Thanks

Jun 23 '06 #3
I try also this:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CheckBoxList1.Items.Add("One");
CheckBoxList1.Items.Add("Two");
CheckBoxList1.Items.Add("Three");
}

if (ViewState["panel"] != null)
{
Panel1.Parent.Controls.Remove(Panel1);
if ( ((int)ViewState["panel"])==2)
Panel2.Controls.Add(Panel1);
else if ( ((int)ViewState["panel"])==3)
Panel3.Controls.Add(Panel1);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Panel1.Parent.Controls.Remove(Panel1);
Panel2.Controls.Add(Panel1);
ViewState["panel"] = 2;
}
protected void Button3_Click(object sender, EventArgs e)
{
Panel1.Parent.Controls.Remove(Panel1);
Panel3.Controls.Add(Panel1);
ViewState["panel"] = 3;
}

but without results.

Help me!

Jun 23 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Treetop | last post by:
is there a way to change the <title> tag from a parent window from a child window in frames?
2
by: RWD | last post by:
I am trying to figure out how to change the target frame in my hyperlink on a DHTML menu. The menu is in one frame and the target frame is called "main" The code is below: Thanks in advance...
2
by: dd | last post by:
I need to know whether an element can move itself to a new parent within the DOM. I can't find any function that offers me such an ability. Here's an example of a hierarchy: -body ....div 1 ...
24
by: Phil Latio | last post by:
Let's say I have a simple web application running with just two MySQL tables. The tables structure is as follows: Table: category category_id (PK) category_name parent_category (FK)...
1
by: HIFIZombie | last post by:
or be able to tell if the selected treenode is a parent node. I have looked at .gettype but how do i check it against something like treeview1.gettype = treeview.nodes.parentnode I use my...
2
by: David Haskins | last post by:
I have a fairly complex interface screen (form) that is comprised of several subforms that perform different, but related activities. I am designing a search/filter form that should be able to...
33
by: sophia.agnes | last post by:
Dear all, consider the following program #include<stdio.h> #include<unistd.h> main() { int pid,*i,j;
3
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RecordSource of a Master Report is: Me.RecordSource = "TableOrQueryName"
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.