Friday, August 2, 2013

Data Bound GridView and Asp.Net Ajax UpdatePanel

I tried loading a couple of grids through an update panel with a timer to try to get the rest of the page to display to the user quickly and do the heavy lifting of these two grids in the background.

I wrapped the two grids in an update panel and added a timer.  I put code in the tick event of the timer.  I loaded the page and it came up quickly and moments later the grids filled in.  Moments after that all of my dynamic data i have created with template fields was erased.  The main data that was being bound was still there.

As I researched it I found that the RowCreated event was firing repeatedly.  I viewed the call stack and saw that it was being fired by system code that I could not see and not by my code.

I tried using session variables to get it to routed around the multiple calls, but the damage was being done before it got to the RowCreated event.  The event also was getting null values for ID fields I was using to populate the grid correctly, which is why the dynamic data was not being displayed.

I did a couple of hours of research, but found nothing specific to my problem, but I did start stumbling upon two properties of the update panel, ChildrenAsTriggers and UpdateMode.  Honestly I don't entirely understand UpdateMode yet, but ChildrenAsTriggers got me thinking that maybe the grid was triggering a refresh of its own somehow after I got everything set the way I wanted it.

I set ChildrenAsTriggers="false".  It required that I have UpdateMode="Conditional".  I think this also required that I have an explicit Trigger tag for the update panel that was set to the Tick event of my timer.

After all that, it appears to be working.

No comments: