macros14
asked on
Dynamic Textbox adding, and recreating them on postback
I have a custom user control that I have built called Rooms.ascx. It contains 2 textboxes, room_name and room_description.
On the page that I want to use the control I have the following code.
<asp:Panel id="pnlRoomCollection" Runat="server">
<MHL:Rooms id="room_1" runat="server"></MHL:Rooms >
</asp:Panel>
<asp:Button id="cmdAddRoom" runat="server" Text="Add Another Room"></asp:Button>
Now when I click cmdAddRoom, I want to add another user control to the panel.
Private Sub cmdAddRoom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddRoom.Click
Dim o As Control = LoadControl("Rooms.ascx")
pnlRoomCollection.Controls .Add(o)
End Sub
This works the first time I click the button, but after I click the button the second time, the user control is created but overrides my previous control. How do I recreate the controls in the panel on postback? I am guess on page_init but I can't seem to find my controls that were on the page before postback in the panel.
On the page that I want to use the control I have the following code.
<asp:Panel id="pnlRoomCollection" Runat="server">
<MHL:Rooms id="room_1" runat="server"></MHL:Rooms
</asp:Panel>
<asp:Button id="cmdAddRoom" runat="server" Text="Add Another Room"></asp:Button>
Now when I click cmdAddRoom, I want to add another user control to the panel.
Private Sub cmdAddRoom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddRoom.Click
Dim o As Control = LoadControl("Rooms.ascx")
pnlRoomCollection.Controls
End Sub
This works the first time I click the button, but after I click the button the second time, the user control is created but overrides my previous control. How do I recreate the controls in the panel on postback? I am guess on page_init but I can't seem to find my controls that were on the page before postback in the panel.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER