473,748 Members | 9,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Controls.Add() for a Web User Control doesn't instansiate its child controls

I'll describe the simplest situation of the problem.

I have a simple Web User Control which only contains a: <div id="bla"
runat="server" /.
I dynamically add it to a page, by performing:

SomeCtl ctl = new SomeCtl();
this.Controls.A dd(ctl);

and of course apply a <% @ Register %tag in order to make SomeCtl known to
the page (is there some more elegant way?).

I override OnPreRender of the control, in order to write some stuff to the
DIV according to some property of the control, but I can't (within the
event code) access the DIV. It is equal to null.
The issue happens of course only when my user control (SomeCtl) is added
dynamically to the page, and not when I place the user control directly
within the page at design time.
Thanks in advance for your help,
Ofer
Mar 25 '07 #1
15 1890
"Ofer Zelig" <of**@newsgroup s.nospamwrote in message
news:eD******** ******@TK2MSFTN GP04.phx.gbl...
The issue happens of course only when my user control (SomeCtl) is added
dynamically to the page, and not when I place the user control directly
within the page at design time.
In which method are you adding the control...?

If you're doing it in Page_Load, try doing it in Page_Init instead...
Mar 25 '07 #2
The host of that user control is a control itself (in this case, a
"regular", design-mode placed one).
I can't put it in Page_Init of the host control, because the code must
access properties of the control which are not available in its Page_Load
event yet...
"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message
news:ek******** ******@TK2MSFTN GP04.phx.gbl...
"Ofer Zelig" <of**@newsgroup s.nospamwrote in message
news:eD******** ******@TK2MSFTN GP04.phx.gbl...
The issue happens of course only when my user control (SomeCtl) is added
dynamically to the page, and not when I place the user control directly
within the page at design time.

In which method are you adding the control...?

If you're doing it in Page_Load, try doing it in Page_Init instead...


Mar 25 '07 #3
"Ofer Zelig" <of**@newsgroup s.nospamwrote in message
news:ek******** ******@TK2MSFTN GP04.phx.gbl...
The host of that user control is a control itself (in this case, a
"regular", design-mode placed one).
OK.
I can't put it in Page_Init of the host control, because the code must
access properties of the control which are not available in its Page_Load
event yet...
In which case, you might find that you need to rethink your logic here a
bit, as I'm pretty sure the problem is that the dynamic creation of the
control is occurring too late in the overall page cycle...

I've seen this many times with dynamically created controls... Create them
in Page_Load, they sometimes work... Create them in Page_Init or
Page_PreInit, they always work...
Mar 25 '07 #4
I can't see a way to change it...
As for the host control (design-time) - as I said, I can't run the
Controls.Add() at its Page_Init event (or any sooner event of course)
because the host control won't be able to access its properties. So it must
run at Page_Load, and in that case - runtime created control's child
controls are always null.
"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
"Ofer Zelig" <of**@newsgroup s.nospamwrote in message
news:ek******** ******@TK2MSFTN GP04.phx.gbl...
The host of that user control is a control itself (in this case, a
"regular", design-mode placed one).

OK.
I can't put it in Page_Init of the host control, because the code must
access properties of the control which are not available in its
Page_Load
event yet...

In which case, you might find that you need to rethink your logic here a
bit, as I'm pretty sure the problem is that the dynamic creation of the
control is occurring too late in the overall page cycle...

I've seen this many times with dynamically created controls... Create them
in Page_Load, they sometimes work... Create them in Page_Init or
Page_PreInit, they always work...


Mar 25 '07 #5
"Ofer Zelig" <of**@newsgroup s.nospamwrote in message
news:e5******** ******@TK2MSFTN GP04.phx.gbl...
I can't see a way to change it...
As for the host control (design-time) - as I said, I can't run the
Controls.Add() at its Page_Init event (or any sooner event of course)
because the host control won't be able to access its properties. So it
must
run at Page_Load, and in that case - runtime created control's child
controls are always null.
As I said, I think you'll have to redesign this piece of functionality
because I don't believe what you're trying to do is possible the way you
have architected it...
Mar 25 '07 #6
I need some more technical answer, specifically why child controls are not
available when the parent is created at run-time.
I'll resubmit the question in a new thread, maybe someone can pinpoint the
issue exactly...

Thanks!
"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
"Ofer Zelig" <of**@newsgroup s.nospamwrote in message
news:e5******** ******@TK2MSFTN GP04.phx.gbl...
I can't see a way to change it...
As for the host control (design-time) - as I said, I can't run the
Controls.Add() at its Page_Init event (or any sooner event of course)
because the host control won't be able to access its properties. So it
must
run at Page_Load, and in that case - runtime created control's child
controls are always null.

As I said, I think you'll have to redesign this piece of functionality
because I don't believe what you're trying to do is possible the way you
have architected it...


Mar 26 '07 #7
Hi Ofer,

I'm not sure if I've fully understood your question, so please feel free to
correct me:

1) You have a web user control which need to load another copy of itself
into its control hierarchy. I think you must have some logic to prevent the
control from recursively loading infinitely, would you please show the
logic here?

2) Normally we use LoadControl to dynamically load a web user control
instead of using "new":

#Overview of user controls vs. custom controls
http://support.microsoft.com/kb/893667
Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.


Mar 26 '07 #8
"Ofer Zelig" <of**@newsgroup s.nospamwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>I need some more technical answer, specifically why child controls are not
available when the parent is created at run-time.
It's to do with the page creation process...

As I've mentioned (a couple of times now), if dynamic controls are created
in Page_Load they mostly don't work properly because they are created too
late to be wired up correctly etc.

However, if they are created in Page_Init or Page_PreInit, then they pretty
much always work...

I appreciate that you find this annoying because of the way you've designed
things, but there's not much I can do about that...

Posting the same question again won't get you a different answer...
Mar 26 '07 #9
Page_Init or anything similar doens't do the work - I checked.
About redesign, I can't think of a simpler model, so it would be a problem.
All that I have, and need, is a regular user control created at design time,
which in turn creates other user controls at runtime. In that case, as I
said, the runtime-generated control doesn't have children (simple HTML
elements), and it seems to me like a bug in the product itself...

"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message
news:Oc******** ******@TK2MSFTN GP05.phx.gbl...
"Ofer Zelig" <of**@newsgroup s.nospamwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
I need some more technical answer, specifically why child controls are
not
available when the parent is created at run-time.

It's to do with the page creation process...

As I've mentioned (a couple of times now), if dynamic controls are created
in Page_Load they mostly don't work properly because they are created too
late to be wired up correctly etc.

However, if they are created in Page_Init or Page_PreInit, then they
pretty
much always work...

I appreciate that you find this annoying because of the way you've
designed
things, but there's not much I can do about that...

Posting the same question again won't get you a different answer...



Mar 26 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3151
by: sleigh | last post by:
Hello, I'm building a web application that will build a dynamic form based upon questions in a database. This form will have several different sections that consist of a panel containing one to many questions. To keep it simple, I'll describe the basics of what I'm trying to design. I've created a TextBox composite control that consists of a label for
6
1963
by: Louise | last post by:
I use Visual Basic .NET Framework 1.1, Visual Studio. I have a Web page (aspx) referencing a control (ascx) that has a placeholder that is assigned one of 2 child controls through buttons. The ViewState of the second child control gets confused with the first child control - the first Text property in the 2nd child gets updated with the first Text property of the 1st child when the 2nd button is clicked after the 1st. For instance,...
2
14021
by: JohnR | last post by:
Let's say I have an MDI parent form with a textbox. If I create an MDI child form and, at runtime, move the MDI child window over the textbox on the MDI parent, the textbox appears in front of the MDI child window. How can I make the MDI child window appear in front of any controls that may be on the MDI parent? thanks, John
1
1535
by: Tony Johansson | last post by:
Hello!! I use VS 2003 and C#. I have sent several mail even tried with crossgroup because I want to find out if my problem is a bug in .NET or if .NET doesn't support what I do. It's only one of these left I suppose. I use project reference where a need to.
1
2457
by: Tony Johansson | last post by:
Hello!! I use VS 2003 and C#. I have sent several mail even tried with crossgroup because I want to find out if my problem is a bug in .NET or if .NET doesn't support what I do. It's only one of these left I suppose. I use project reference where a need to.
3
1687
by: Mike Collins | last post by:
I have some controls that I am creating dynamically. After the user finishes entering their answers in these controls, I would like to iterate through these controls and get the answers out. I have tried a couple of ways, but do not see those controls there. Can someone please help? Below is snippett of code to show how I am adding the controls and "for now" how I am trying to read them back. foreach(Question.BuildingBlock buildingBlock...
15
6520
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt accept other controls. The control i drag drop on it becomes the child of my custom control's parent form and not the child of my custom control. Then i added this line "" before my custom control class (i dont know what this line does). Now
3
397
by: Ofer Zelig | last post by:
I'll describe the simplest situation of the problem. I have a simple Web User Control which only contains a: <div id="bla" runat="server" /. I dynamically add it to a page, by performing: SomeCtl ctl = new SomeCtl(); this.Controls.Add(ctl); and of course apply a <% @ Register %tag in order to make SomeCtl known to
6
1789
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... Tried posting this on Build Controls but then saw that's a pretty slow group... Kind of a typical request from product management - they want to be able to swap in different 3rd party controls depending on their whim and the day. In this case, they want to support FreeTextBox and Cute Editor interchangably. I've been trying to put together a container control derived from
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8237
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.