473,226 Members | 1,666 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,226 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 2245
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
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.