Problem handling DataGrid TemplateColumn Databinding Event

Discussion in 'ASP .Net Datagrid Control' started by Glenn Owens, Jul 9, 2004.

  1. Glenn Owens

    Glenn Owens Guest

    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
     
    Glenn Owens, Jul 9, 2004
    #1
    1. Advertising

  2. Glenn Owens

    Glenn Owens Guest

    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
     
    Glenn Owens, Jul 12, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob
    Replies:
    0
    Views:
    632
  2. Peter Larsson
    Replies:
    0
    Views:
    280
    Peter Larsson
    Mar 9, 2005
  3. jobs
    Replies:
    0
    Views:
    1,762
  4. aamir
    Replies:
    4
    Views:
    1,019
    Chuck
    Sep 16, 2008
  5. Earl Teigrob
    Replies:
    1
    Views:
    444
    Shravan
    Mar 1, 2004
Loading...

Share This Page