473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

User Web Control Load Problem

I have built a composite user web control that I want to create dynamically.
The form will contain a variable number of these controls and as well some
of the contents of the user web control itself are dynamically created
controls.

I create as follows:
wcGroupControl oGroupControl = new wcGroupControl();

I then tried calling methods of the control passing dynamic controls as
parameters that need to be added to the web controls on the control. Well I
quickly realized that the controls within the UWC are not created until the
control is actually rendered on a form, doh!.

Is there a way around my delema? Should I create the controls contained
within UWC in the constructor instead?
Nov 18 '05 #1
3 2249
Hi Eric,
Thanks for posting in the community!
From your description, you've developed a custom web server control which
is used in some certain web pages( static or dynamically added). Also, the
control is a composite control and it has a member function which takes a
control parameter so as to let it add some dynamically created sub
controls. However, you found that the custom server control's controls
structure may haven't been completed when the certain add control function
is called to add sub control, that'll cause some problem at runtime, so you
wonder whether there is any way to ensure the controls strucutre has been
completely constructed so that we can call its function to add dynamic sub
controls correctly, yes?
If there is anything I misunderstood, please feel free to let me know.

As for this problem, here is my suggestions:
Yes, as you've found that when the server control has completely
constructed its controls struture is unexpected at runtime. Generally, the
server control will call createchildcontrol method to construct its
controls collection after the "Init" event, however, this all depends on
the lifecycle of its container page since a control reside on a certain
page , do you think so? So if we directly access a certain server control's
control collection and added some dynamically created sub controls(in
Page's OnInit or Page_Load event) , it will cause some problem since the
entire control strucutre of the server control hasn't been constructed.
However, there is a member function named "EnsureChildControls" of
System.Web.UI.Control which is used to ensure that the control's controls
structure has been completely constructed. Here is the description in MSDN:
----------------------------
This method first checks the current value of the ChildControlsCreated
property. If this value is false, the CreateChildControls method is called.

ASP.NET calls it this method when it needs to make sure that child controls
have been created. In most cases, custom server control developers do not
need to override this method. If you do override this method, use it in a
similar fashion as its default behavior.
-----------------------------
For more detailed info on it, you may view the following references in MSDN:
#Control.EnsureChildControls Method
http://msdn.microsoft.com/library/en...webuicontrolcl
assensurechildcontrolstopic.asp?frame=true

#Control.ChildControlsCreated Property
http://msdn.microsoft.com/library/en...WebUIControlCl
assChildControlsCreatedTopic.asp?frame=true

So as for your situation, you may call the custom server control's
ensurechildcontrols method before you call the add dynamic control method
so that the dynamically created control can be correctly added into the
control's Controls structure, how do you think of this?

In addition here are some other tech articles on developing Custom
Composite server control and dynamically add controls on ASP.NET page, I
believe they're also helpful to you:

#Developing a Composite Control
http://msdn.microsoft.com/library/en...lopingcomposit
econtrols.asp?frame=true

#HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET
http://support.microsoft.com/?id=317794

Please check out the preceding suggestions and items. If you have any
questions on them, please feel free to post here.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 18 '05 #2
Steven,
Thank you for the reply. See notes below.
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:3R**************@cpmsftngxa07.phx.gbl...
Hi Eric,
Thanks for posting in the community!
From your description, you've developed a custom web server control which
is used in some certain web pages( static or dynamically added). Also, the
control is a composite control and it has a member function which takes a
control parameter so as to let it add some dynamically created sub
controls. However, you found that the custom server control's controls
structure may haven't been completed when the certain add control function
is called to add sub control, that'll cause some problem at runtime, so you wonder whether there is any way to ensure the controls strucutre has been
completely constructed so that we can call its function to add dynamic sub
controls correctly, yes?
Exactly.
If there is anything I misunderstood, please feel free to let me know.

As for this problem, here is my suggestions:
Yes, as you've found that when the server control has completely
constructed its controls struture is unexpected at runtime. Generally, the
server control will call createchildcontrol method to construct its
controls collection after the "Init" event, however, this all depends on
the lifecycle of its container page since a control reside on a certain
page , do you think so? So if we directly access a certain server control's control collection and added some dynamically created sub controls(in
Page's OnInit or Page_Load event) , it will cause some problem since the
entire control strucutre of the server control hasn't been constructed.
However, there is a member function named "EnsureChildControls" of
System.Web.UI.Control which is used to ensure that the control's controls
structure has been completely constructed. Here is the description in MSDN: ----------------------------
This method first checks the current value of the ChildControlsCreated
property. If this value is false, the CreateChildControls method is called. Sounds exactly what I need. I will try this.
Thank you ASP.NET calls it this method when it needs to make sure that child controls have been created. In most cases, custom server control developers do not
need to override this method. If you do override this method, use it in a
similar fashion as its default behavior.
-----------------------------
For more detailed info on it, you may view the following references in MSDN: #Control.EnsureChildControls Method
http://msdn.microsoft.com/library/en...webuicontrolcl assensurechildcontrolstopic.asp?frame=true

#Control.ChildControlsCreated Property
http://msdn.microsoft.com/library/en...WebUIControlCl assChildControlsCreatedTopic.asp?frame=true

So as for your situation, you may call the custom server control's
ensurechildcontrols method before you call the add dynamic control method
so that the dynamically created control can be correctly added into the
control's Controls structure, how do you think of this?

In addition here are some other tech articles on developing Custom
Composite server control and dynamically add controls on ASP.NET page, I
believe they're also helpful to you:

#Developing a Composite Control
http://msdn.microsoft.com/library/en...lopingcomposit econtrols.asp?frame=true

#HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET
http://support.microsoft.com/?id=317794

Please check out the preceding suggestions and items. If you have any
questions on them, please feel free to post here.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



Nov 18 '05 #3
Hi Eric,
Thanks for your followup. Hope that'll help you resolve your problem.
Meanwhile, if you meet any further problems or need any help, please always
feel free to let me know.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4

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

Similar topics

6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
1
by: Kris van der Mast | last post by:
Hi, been a while since I posted a question myself instead of trying to help others out. I'm refactoring an existing web app that uses dynamic loading of user controls and a lot of...
3
by: Matej Kavčič | last post by:
Hello, i have one problem. I use loadcontrol in default.aspx page. On page i have placeholder and on load i with loadcontral load dynamic some user control. Some times i must load same user...
2
by: Sam Kuehn | last post by:
There has been a lot of articles on how to load user controls at runtime in the Init() method. UserControl myControl = (UserControl)LoadControl(stringControl); I add the control in the Init()...
6
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all...
0
by: jonelling | last post by:
I am having a problem where the page load event is not being fired for certain user controls that I load dynamically in placeholders. Here is what I'm doing in brief, with full test code supplied...
8
by: David Lozzi | last post by:
Howdy, I have a user control that is a report to display data. On the page the control is inserted in, I have filter options to filter the report. When I try to do something like this, nothing...
0
by: John Smith | last post by:
I still have not gotten this damn thing figured out and I'm asking for help one last time before I give up on it. I have a user control that contains a paged gridview control. The master page...
0
by: davidr | last post by:
Hi, I have a panel that I load user Control in no problem. The problem arrises when I do a post back on one of these user controls. I have button it does a click event. In this click event I...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...

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.