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.

8/15/2008 6:44:45 AM 93655 articles. 6 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 1

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, which isn’t guaranteed to work.

So you should try to check if you have modify the property in the control’s OnInit phase, if so, just remove it.

and here is the original link,


Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
8/19/2008 8:38:13 AM
8/19/2008 9:40:01 AM

Similar Artilces:

How to Load User Control From Within User Control
I'd like to load a user control, that has its code-behind compiled into an assembly, from within another user control. The user control you see below is used as a page template, contained within a .aspx file. There is no code in the MySite.Web.UI.Pages.PageTemplate class. <%@ Control Language="C#" Inherits="MySite.Web.UI.Pages.PageTemplate" %> <%@ Register TagPrefix="mysite" Namespace="MySite.Web.UI.Controls" Assembly="MySite.Web" %> <div id="container"> <div id="pageHeader"> ...

UpdatePanel within a web user control resets data of controls outside the user control
Hello, I have a usercontrol on my page which displays a running marquee text. It makes use of an UpdatePanel (within the user control) to refresh the marquee text (within the updatepanel) at periodic intervals. For this I added a timer control and its tick event as an async postback trigger for the UpdatePanel. I have a lot of textboxes and dropdown list boxes (all with runat=server) on the page outside the above user control. These are also contained in different UpdatePanels. Problem is, when the user control does a postback to refresh the marquee text, it causes some of...

User Control Within UserControl
If I have a user control A and then inside it a user control B embedded/referenced within it.  User Control A has a panel defined (cpeNewUser) that I want to manipulate from the code behind of User Control B based on some event that happens.So putting this in my code behind of User Control B won't work as it has no idea of cpeNewUser:cpeNewUser.Collapsed = true;So is it because only at runtime they are married up and because of this you cannot access each other's objects at compile time?  How would I get this to work becuase I'm using all user controls inside a AJAX Too...

Using user control within another user control
Hi, Can I register and instantiate a user control within another user control. Yes, of course you can.  If you are doing it dynamically, then you have to remember that you have to do it in every postback there after. <%@ Register Src="usercontrol1.ascx" TagName="TagName" TagPrefix="uc1" %> <uc1:TagName ID="UserControlID1" runat="server" /> ...

Calling user control within another user control
I want to call one user control within another user control, but I get all sorts of errors when I try to do this. Is this possible ? if so how to go about it. {code} <%@ Control Language="C#" AutoEventWireup="true" CodeFile="i_top.ascx.cs" Inherits="i_top" %> <%@ Register TagPrefix="agg" TagName="siteowner" Src="~/templates/i_siteowner.ascx"%> <div id="navbar"> <h2 class="hide">Site wide navigation</h2> <ul> <li><a href='~/default.aspx' id...

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...

reference user control within another user control
1) user control named EditBar (used for appending editing feature buttons specific to page mode - add, search, delete) <Script Control Language="vb" runat="server" > Public Sub EditBar_CustomersAdd() ctl_EditBar.Text &= "<img src=""/tims/images/add.gif"" width=""24"" height=""24"" border=""0"" alt=""Add a Customer"">" End Sub .... other methods omitted for simplicity </Script> <asp:Label id="ctl...

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">  ...

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 –...

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 ...

Web resources about - How to load user control within another user control? -

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Otway fire still out of control but no threat to Falls Festival
Firefighters are battling to contain an out-of-control Great Otway National Park fire ahead of an expected hot and windy weather spike on Christmas ...

Review: Sugr Cube, the cute wooden portable AirPlay speaker with gesture controls
... rarer, pretty ones even rarer and the Sugr Cube goes one step further in its bid to stand out from the crowd: it offers gesture-based control. ...

You can control this family’s Christmas lights over the Internet
... Horrible disaster waiting to happen? You be the judge. You've never met Ken or Rebecca-Ellen and you probably never will. But you can control ...

This is how Amazon is taking control of delivery – and taking it away from UPS
As Amazon searches for ways to speed up delivery, the company this year made big strides toward cutting out the middle man and establishing a ...

Virginia AG Ends Concealed Reciprocity with 25 States for Lack of Gun Control
Virginia AG Ends Concealed Carry Reciprocity With 25 States For Lack Of Gun Control

You can control this family's Christmas lights over the internet and the results are mesmerising
... as they see fit. Visitors are greeted with a live webcam of the Fairbanks, Alaska house — pictured above — as well as a bank of controls for ...

Afghan officials: Key district besieged by Taliban still under state control
"Taliban rumors that they have captured the district are not true," says local official trapped for 3 days before government reinforcements arrived ...

NBA Stars Come Out In Support Of Gun Control
NBA Stars Come Out In Support Of Gun Control

How Sepp Blatter Lost Control Of His Monster
If Sepp Blatter could take a step back and look at the bigger picture, forgetting for a moment that today’s eight-year ban from all soccer activities ...

Resources last updated: 12/26/2015 8:37:44 AM