dynamically load user control from another user control

Is it possible to dynamically load a user control from another user control?  I have an aspx page where I have declaratively included a user control.  Now, within that user control I want to dynamically load another usercontrol onto the page based on some business logic.  Does this even make sense?

So, here's the scenario:
aspx page:
<%@ Register TagPrefix="header" TagName="links" Src="~/usercontrols/toplink.ascx" %>
<asp:Content ID="ContentBody" ContentPlaceHolderID="cphBody" runat="Server">
        <asp:PlaceHolder ID="dynContent" runat="server"></asp:PlaceHolder>
</asp:Content>

toplink.ascx page:
protected void Page_Init(object sender, EventArgs e)
{
     if (someLogic == true)
     {
         Control dControl = LoadControl("usercontrols/dynamic.ascx");
         dynContent.Controls.Add(dControl);  <====problem ???how do I get access to dynContent????
       }
}

0
porkchop
3/4/2008 3:10:24 AM
asp.net.web-forms 93655 articles. 2 followers. Follow

1 Replies
322 Views

Similar Articles

[PageSpeed] 19

to get back access to dynContent use

 Control dControlreference =  dynContent.findcontrol("dControl");


Vikram
www.vikramlakhotia.com


Please mark the answer if it helped you
0
vik20000in
3/4/2008 3:24:44 AM
Reply:

Similar Artilces:

Problem in accessing web form data in user controls when create user control dynamically
HI. I have a problem using web user control. I designed a user control named NewsForm. This user control contains some web form elements like <asp:textbox>. When I add it in an .ASPX page, all things may be true. I can know which user filles in textbox (for example and other controls) <%@ Register TagPrefix="uc1" TagName="NewsForm" Src="NewsForm.ascx" %> and <UC1:NewsForm id="newsForm" runat="server"></UC1:NewsForm> But when i create it in code behined dynamically, however user control has web form controls but their value are blank for example //aspx co...

Web User Control to Web User Control...
Hi, I have 2 User controls on a page and want Control1 to call a method of Control2. Is this Possible? Example: Con1 = Datalist showing products, each with a Quantity Box and a Button. Con2 = Repeater showing Cart Preview (name, Price) in page.aspx. When I click on the button on the DataList in Con1 it adds the item into the Session based Cart. However it does not update the Cart Preview. I need to call BindPreview() in Con2 in order to update the Cart Preview... Does that make sense? argh! any help much appreciated! PeteWeb Design Nottingham, UK Well I can call BindPreview() from m...

How to load user control within another user control?
I have many user controls. One of them is Banner.ascx which I may load it within anothers. I tried to load Banner.ascx within Footer.ascx but  I got an error "The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases."Any ideas?Any answer is appreciated highly.Thanks. Hi friend, Check the following paragraph, perhaps it can help you,   Does your application run on .NET Framework 2.0 or above? If so, from the error message, the cause of the error is that you are trying to access a property on a child control in OnInit phase, wh...

Web user control inside update panel replace with another web user control
 Hi there. I have a page with a menu. an and then the content. My thing is. That i have the update panel, and inside that i have a regual panel in which i add the Web User Controls i need. Which all works fine. My problem is. That i i have a submit funcion on almoast all the Web User controls. What i would like is that i inside that update panel, can dispose the original Web user Control and then add a response Web User Control. In normal language. Is there a way that i can load one web user control into antoher and then disposose the original? Thanks in advance hello. well, what ...

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

dynamically load user controls within a user control problem
I am dynamically loading a set of user controls from within a user control (static user control). I add my user controls, at runtime, to the controls collection of a Panel control that is on my static user control. I reload my dynamic user controls each time my static user control runs its Page_Load event. Everything works fine, but my dynamic user control button events do not fire. Any help appreciated.   Regards, Paul. Hi,  how and where do you add the event handler to your user control button? I have a page (aspx) that has a user control (static) on it...

How to access a user control from another user control in a Wizard control
My page has a wizard control and each step is a user control.  I could find the value of a control in step1 user control in the wizard page but not in step2 user control.From wizard.aspx.vb – it worksDim m_title As DropDownList = CType(Me.PersonalBox1.FindControl("ddlTitle1"), DropDownList) Question:How can I find the value of a control(textbox or dropdownlist)in step1 user control from step2 user control? I want to find “PersonalBox1.FindControl("ddlTitle1")” from Step2 AddressBox1. I have tried several ways to access it but no luck. From AddressBox.ascx.vb –...

User Control controls not created when dynamically creating user control
  Have created a user control for displaying and editing a dynamically number of values. The user control contains two labels and an edit box. When dynamically loading the user control I get an error when the control itself tries to change setting on the fields within the user control.   Why doesnt this work? It works okay if I dont load it dynamically but create a user-control-instance in the aspx-page but thats no solution.   Thankyou!     Here is my code:   ucDataValue.ascx   <%@ Control Language="C#" AutoEventWireup="true&...

Update Controls in Another Dynamically Loaded User Control
I have looked at other articles to try and figure this out and I still don't quite understand.  This article http://forums.asp.net/t/1117746.aspx was somewhat similar, but the controls aren't loaded dynamically. Scenario:  The web application uses an old style Page template.  The template has specified regions on the page such as header, leftnav, body, rightnav, and footer.  The application's actual .aspx pages inherit from this control, but there is no HTML markup at all.  The individual pages code behind specifies which controls to load.  Thi...

I have a web user control being used by another web user control, but the one being used will not display the labels in the resx file.
I am using DotNetNuke version 3.13 (might be 3.013) on a Window's XP machine, SP2. I have what I find to be an extremely odd situation. I have a project called TDS.Controls. This project is a web control library. Each control has its own resx file, which is located in the App_LocalResources directory. Each control inherits from Framework.UserControlBase, just like DotNetNuke's User control in DNN\Controls\User.ascx.vb. As a matter of fact, this control is doing the exact same thing I am trying to do. It is a web user control with its own resx file being used by another web user control (See ...

(How) Can i use the form elements of a user control from another user control???
Hi, i have a user control with 4 other user controls. Actually i have 4 panels and each user control is inside a panel. Its like a 4 page form which are all connected to each other. Is it possible to have access to web controls that i have in my user controls from the main user control. In my main user control i have a submit button and a tab list. User can browse through the tabs and each tab is bound to a panel. so clicking on tab1 makes panel1 visible which holds the first user control, second tab makes second panel visible and the rest invisible and the second panel holds the ...

Loading a dynamic user control on main page from current user control
Hi,  Please help,  I've posted this a week ago and never got a response.  I'm still stuck on the same problem.I have a panel that I load user Control in no problem.  The problemarrises when I do a post back on one of these user controls.  I havebutton it does a click event.  In this click event I will do somedatabase updates, then I will use reflection to call a method in theparent (this.page) to load the new user control.  Its at this pointafter it loads the new user control that it throws the error "Thecontrol must be placed inside a form tag...

Add User Control to table cell in another User Control dynamically
Hi.. Right now im using one user control in an aspx page as.. <%@ Register TagPrefix="cc1" Namespace="cssc.Web.Controls" Assembly="Clock" %> <div id="lCurrTime_container" style="BORDER-RIGHT: black 1px solid; BORDER-TOP: gray 1px; DISPLAY: block; FONT-WEIGHT: bold; FONT-SIZE: 7pt; Z-INDEX: 102; LEFT: 0px; BORDER-LEFT: gray 1px; WIDTH: 120px; COLOR: black; BORDER-BOTTOM: black 1px solid; POSITION: absolute; TOP: 0px; HEIGHT: 16px; BACKGROUND-COLOR: white; TEXT-ALIGN: center"> Current time:  <cc1:clock id="Clock2" runat="server" UseExternalJS="true" DateTimeFormat=...

Javascript inside "web user control" not run if load "web user control" under ajax UpdatePanel
I have this problem and please if some can help me, I place here a sample code to see, but in my real problem the web user control have a very complicate javascript. I have a web user control that have some javascript inside, let say for example.1 <script type="text/javascript" > 2 function RunMe() 3 { 4 alert("Client id:<%=ClientID%>"); 5 } 6 </script> 7 8 9 <a href="javascript:RunMe()">Run javascript</a> a simple call to a simple javascript, inside the web user control And now I have...

Web resources about - dynamically load user control from another user control - asp.net.web-forms

iPhone 5 A6 chip to dynamically up-clock up to 1.3GHz (and downclock too)?
Interesting video from our friends at TLDToday: If this is not just a Geekbench app glitch, it could indicate why that A6 processor is so 2X ...

Apple's Lightning port dynamically assigns pins to allow for reversible use
... a closer look at how Apple's new Lightning connector works, and has come to the conclusion that the 8 pins on each side of the plug are dynamically ...

iPhone 5 Lightning port dynamically reassigns pins
... of Apple's Lightning USB cable shows that the pins on the plug aren't arranged symmetrically, suggesting that the Lightning port can dynamically ...

Urlbox Launches Screenshots-as-a-Service Platform to Dynamically Update Galleries
... changes. Launched yesterday, Urlbox allows anyone with a gallery displaying website screenshots to automate the process and keep them dynamically ...

Everything.me launcher dynamically adapts to what you’re doing right now
... phone according to what you’re doing. Perform a search for ‘football’ and your background will change to the NFL logo. A launcher that dynamically ...


A YouTube Experiment Resizes the Player Dynamically
There's a new YouTube experiment that changes the video player's size, depending on the browser window's size. When resizing Chrome's window, ...

Apple Granted “Dynamically Changing Cursor for User Interface” Patent, Originally Filed in 2003
... a utility patent that covers the use of the mouse cursor that changes according to the context of the task it is engaged in. Called a “Dynamically ...

Atmel's FPSLIC II Dynamically Reconfigurable SoC Supports "Silicon-Sharing" For Peripherals & Interfaces ...
Silicon-Sharing Fits 200K Gate Design into 40K Gate FPSLIC II's, Cuts Power Drain by 97%

Everything.me Launcher Wants to Dynamically Change Phones Based on Location, Interests, and Mental State ...
What if your phone’s launcher dynamically changed based upon interests, your location, or topics you had in mind at a specific moment? A new ...

Resources last updated: 12/24/2015 10:45:18 AM