Problem handling DataGrid TemplateColumn Databinding Event

G

Glenn Owens

I have spent several hours trying to research and/or fix the following
problem:

Environment:
VB.Net 2003

Scenario:
I have a dynamically generated DataGrid (all columns are
templatecolumns added at runtime). One of the columns contains a
custom control. In the InstantiateIn method of my
TemplateColumnFactory I:

1) Create a deep copy instance of the custom control (provided via a
TemplateColumnFactory construction parameter),
2) Add a DataBind event handler for the custom control,
3) Add the control to the templatecolumn.

In the associated DataBind eventhandler (also located in the
TemplateColumnFactory) I raise a Public Shared event which exposes the
DatabBinding of the custom control to the, in this case, aspx
code-behind (web Page - which has already added an EventHandler for
the Shared event).

Control DataBind --> Factory raiseEvent --> aspx EventHandler

This all works great the first time...

Problem:
On each subsequent postback, the aspx EventHandler handles the rasied
event an incremental number of times for each control in the DataGrid
i.e:

First postBack aspx EventHandler handles the raised event twice
Second postback aspx EventHandler handles the raised event three time

and so on...

HELP!!!:
First I really need to understand why this is happening. Second, I
really need to get this fixed quickly.

Thanks,
Glenn
 
G

Glenn Owens

OK, here's what I did (as a work-around)...

Instead of attaching a DataBinding eventHandler in the InstantiateIn
method of the TemplateColumnFactory (for the custom control) I used
the ItemDataBound event on the Datagrid to process/hydrate the Custom
control in the DataGrid TemplateColumn (from the .aspx code-behind).

This effectively eliminated the redundant event processing. While this
"solution" will keep me moving along I would really like to understand
why this redundant event processing occurred. Ideally, I'd like to
publish the databinding event for the custom control (this would be
far more intuitive for other consumers of the TemplateColumnFactory).

I hope that someone has some thoughts/ideas.

Thanks,
Glenn
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top