Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adding Web Control To Page In Page_Load
Message
From
25/02/2010 16:41:19
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01451004
Message ID:
01451070
Views:
23
Hi Kevin,

I have complete sites running with userControls for the content area. I change content by changing the control and not leaving the page. I don't use a Panel control, I use a PlaceHolder control. Then you can do a placeHolder1.Controls.Add. You will need to do a bit of work if you change out the controls on the page but I would be happy to share some code with you on how to do it. Here is a simple put the control on part.

Here is the ASPX markup
<asp:Content ID="Content3" ContentPlaceHolderID="cphMainContent" runat="server">
    <div id="content">
           <mm:mmPlaceHolder ID="holdResourcesContent" runat="server">
            </mm:mmPlaceHolder>
        </div>
</asp:Content>
Here is the code behind
protected void Page_Load(object sender, EventArgs e)
{
     // Create the Control
     ucResourcesLinks linksControl = (ucResourcesLinks)Page.LoadControl("~/ControlsResources/ucResourcesLinks.ascx");

     this.holdResourcesContent.Controls.Add(linksControl);
}
If you are going to swap controls while on the page, let me know and i can show you what I do to make sure the controls don't get strange on you.
Tim


>I'm completely new to ASP.Net so...
>
>I created a user control with some fields on it. I want to add it to a page in Page_Load. I'm assuming that this is the place to do it.
>So I dropped a panel on the page, then in Page_Load I have:
>
>
>Params_AssCumLtDetail Params = new Params_AssCumLtDetail();
>pnlParams.Controls.Add(Params);
>
>
>When I run it, I don't see anything.
>
>When I do this:
>
>
>Label myLabel = new Label ( );
>myLabel.Text = "Sample Label"
>pnlParams.Controls.Add ( myLabel );
>
>
>The label appears.
>
>So what's wrong here?
Timothy Bryan
Previous
Reply
Map
View

Click here to load this message in the networking platform