DataBoundLiteralControl loses plot

I

Iain

I've got a databound templated custom control.

The data is a list of simple objects which (in essence) have a name and a
percentage value in them.

This control works fine - mostly.

Now I can navigate between different sections of my system showing this
control and often it seems to work.

Sometimes however it crashes with an index out of range error.

If I trace into the code, what I'm doing is
looping through the list,
creating a template container control
instantiating the template in it
Adding the container control to the Controls collection
Calling DataBind on the container

What I'm seeing is that before the container control is added to the
controls collection it has its _dataBountLiteral value and _staticLiterals
values absolutely correct (in this case there are 2 dimensions (with null
values in) for the _dataBoundLiteral and 3 for the statics).
then I call Controls.Add(container) and the _dataBoundLiterals and
_StaticLiterals values are changed as the container control is added to the
collection.

In this particular instance this is the second time the control has been
created in this page lifecyle, the first time from viewstate with an event
being rasied and bubbled up and the section switched.

This bubbling caused the list (which contains the bound data) to be changed
and I then clear the controls collection and refresh with the new data.

In this instance the new data picks a different template with fewer
variables to be incorporated.

What is happening when the container control that I've just constructed is
added to the Controls list is that the values I've just set for that
control are replaced with the values from the first creation of the
control.

I'm actually track the DataBoundLiteralControl object during this process
and something is most definately resetting the binding information during
the Controls.Add process.

So in short, when a templated databaound control is recreated (in
Page.OnLoadCompleted) the binding information in DataBoundLiteralControls
appears to be replaced with the equivalend information from the control
proviously in that location in the controls collection.

Sorry if this question is a tad long, but it's not a simple issue.

Any help or pointers gratefully received.


Iain
 
I

Iain

On Wed, 7 Jun 2006 20:07:25 +0100, Iain wrote:

....
So in short, when a templated databaound control is recreated (in
Page.OnLoadCompleted) the binding information in DataBoundLiteralControls
appears to be replaced with the equivalend information from the control
proviously in that location in the controls collection.

The problem appears to be due to the controls values being refreshed from
the ViewState when it is added to the control collection.

If you call ClearChildViewState after clearing the Controls, the problem
goes away.


Iain
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top