UserControls-Multiple usercontrols w/forms on 1 pa

EgyCheETah

New Member
I am having a problem with user controls that contain input controls with a <form runat="server> tag.<BR><BR>When I place a user control on a page with an existing <form runat="server> tag it gives me an error that you are only allowed 1 form that has "runat server"<BR><BR>I need to have the original page AND the user control to have input items, the user control adds additional specific input criteria based upon additional variables.<BR><BR>Thanks in advance,<BR><BR>erkedI haven't tried this, but can you create the ASCX page without the form tag? Then let the form items in the control page fall under the parent ASPX pages form tag?<BR><BR>Just a thought.Resolution: The real issue involved was the placement of the usercontrol, when adding the usercontrol it just placed it after the form (the usercontrol has no <form> tags to cause the multiple <form> error). To MAKE SURE that the usercontrol gets placed WITHIN the <form> tag you need to create a "placeholder" control. Then when you add your usercontrol you add it to this "placeholder's" control collection - this will place it at the exact spot within the HTML code that the placeholder is at, just make sure the placeholder control is in the <form> tag. An additional benefit is that the placeholder label does not show up and only the contents of the usercontrol show (exactly what I wanted).<BR><BR>1. Add a label in the <form> tag called lblUserControlPlaceHolder<BR><BR>2. In the codebehind add:<BR><BR>Dim ucMyControl As UserControl = LoadControl(("MyUserControl.ascx")<BR>lblUserControlPlaceHolder.Controls.Add(ucMyControl )
 
Back
Top