473,386 Members | 1,860 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,386 software developers and data experts.

Help - Server Control Hierarchy Built Twice

I'm sure this is a design question that is commonly encountered, but I
can't find any resources which explain how to solve it. I would deeply
appreciate any advice.

Basically, when building a composite server control, I'm trying to
avoid having to build the control twice. Here's why this happens:

The routine for building the control can be called from two places:
(1) CreateChildControls, or (2) DataBind. If DataBind is called, it
sets ChildControlsCreated to false, and creates the controls itself.
If it isn't called, then CreateChildControls is automatically
invoked, and creates the controls from the ViewState. Great! This
works fine.

However, several of the child controls can change the state of the
control – essentially, the control has a table, and the table can be
rendered in different ways, so you can select different rendering
options from the control (horizontal, vertical, etc.) via
dropdownlist controls.

When one of these controls is selected, it registers an event, and
calls a routine to change some properties of the control that tell it
to render differently. However, postback events like this occur after
DataBind, and more importantly, after CreateChildControls.

If one of these events is raised, when CreateChildControls is invoked,
it doesn't know that the properties of the control are about to
change, and therefore the rendering it will perform is about to be
obsolete. What happens is that it builds the control hierarchy, then
later the event is called, which changes how the control hierarchy
should look, and so it MUST REBUILD the control hierarchy again to
respond to the changes posted by the event. Therefore, I'm building
the control hierarchy twice.

I assume I'm doing something drastically wrong in my design here, but
I can't figure out how I should handle this differently. Please, any
advice, links, pseudocode, admonishments would be greatly
appreciated.

Thanks in advance.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 19 '05 #1
1 1511
If I understand you correctly, a (some?) child controls can change
properties of the control itself, which effectively affects the child
controls themselves.

In case I am correct, then the answer will be no. Well, lets say
there's just not a proper way to do it. * The reason for this is
relatively easy, once you understand what is going on. Basically, after
a postback, an event is raised which you have to handle to do your
stuff. However, that event wont be raised if the control does not get a
chance to do so. It will (normally) only be given a chance to raise an
event by the page (based on postback data, etc.). But if the control
does not exist, or is just not participating in the control hierarchy,
the page will not be able to find that control. And the event would not
be raised.

Long story short: the control has to be there after a postback, because
otherwise you will not be able to handle the event. However, you want
to re-create the child controls once you handle that event, which means
you are creating the child controls twice (however they are not the
same as the previous set of child controls, right?). You can't do
anything about that.

* It can be done if you would check the postback data at a very low
level, which gets quite ugly and is probably not worth the hassle.

(As a sidenote: this also happens in case of for example a datagrid. If
you go into edit mode, you set the EditItemIndex (in edit's
eventhandler) and you end up re-binding the data. Re-binding the data
means the grid will re-create its controls.)

HTH.

----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl

Nov 19 '05 #2

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

Similar topics

8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
22
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
1
by: Gerald Klein | last post by:
Does anyone know if when databinding is called on a parent object, does that also subsequently get called on all children objects?? thanks
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
2
by: Scott Kelley | last post by:
I have a control inside of an asp:Table control. Once I place it in there, I can't seem to edit it any more (Double click to add events, drag to reposition, etc...). If I use an HTML table, no...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
28
by: Tim_Mac | last post by:
hi, i'm new to .net 2.0, and am just starting to get to grips with the gridview. my page has autoEventWireUp set to true, which i gather is supposed to figure out which handlers to invoke when...
2
by: Hongbo | last post by:
Hi, I have a web site built in ASP.Net 1.1 running on production server. It's the version 1.0. Now I need to build the version 2.0 for this web site. The version 2.0 will be built based on the...
53
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.