Thursday, 20 April 2006
This is just a quickie.  I'm re-doing a rather large input form using a DataGrid to let the user navigate it, filter it, sort it, etc. Looked like an ideal opportunity to try adding AJAX into the mix, to avoid posting the whole thing back. It thought it was working very nicely, then I noticed that the rows were getting incorrect contents when I was filtering the grid -- some of the values were staying in place and being combined with the rows that "slid up" because of the filtering.  One column in the grid has a dynamically loaded user control based on the contents of the row. The user control can display between 1-4 text boxes and contains validation controls as well. This  column was not displaying correctly when filtering.

I figured the AJAX solution I am using was buggy, so I went to the AJAX package's user forum and found a post regarding a similar problem.  One respondent stated that this was not an issue with AJAX, but with the DataGrid and the way it worked with ViewState to create the controls (GridView in 2.0 is supposedly immune). Sounded plausible and would be simple enough to test.

One of the nice things about the AJAX package I'm using is that it is fairily non-intrusive, so I split out all the basic page code into a base class and created two pages that inherited from it -- one AJAX-enabled and one conventional.  This way I'd be able isolate AJAX specific problems from DataGrid problems without having to change the code in two places. 

I ran the conventional page, applied the filter, waited for it to postback, waited, waited, and son-of-gun, the same exact issue as the AJAX-enabled grid. Mangled up user controls. 

Not desiring to become a DataGrid ViewState expert this morning and delve into how the control tree was being screwed up, I took a guess that the control IDs forthe user control might be responsible.  I added some code to explicitly set the ID property to a unique value for each control when they were created. Voila!  No more mangled contents.  Everything was rendering as expected on both the conventional and Ajax-enabled grids.

Since I was not setting the IDs for these explicitly, they were all named ctl0.  Now, the full name inlcuded the gridname and row qualifier as well, dgParameters__ctl3__ctl0 for example, but after applying the filter,  there is no way for the grid to differentiate between the old row three and the new row three, and hence strange results appear.  By explicitly setting the ID on the user control to something unique this no longer happens and I can get back to getting this all working.

More on the AJAX goodies soon.

Thursday, 20 April 2006 09:22:51 (Eastern Standard Time, UTC-05:00)   #     Comments [0]  | 

Theme design by Dean Fiala

Pick a theme: