I have encountered a niche issue I'm trying to solve. I have a grid with EnableViewState set to false. Based on this, the control state within the grid is used to manage things like sort expressions.
My issue is simply this:
- Page load
- Programmatically add columns to a grid
- On the UI, sort on a column, and its name for example is 'My Column', this becomes 'My Column ASC'
- On our app are objects in which its name we can add as a column to the same grid
- Somewhere in our app I rename the object's name to something else like 'My New Column' - note the sort expression is still 'My Column ASC'
- Back to the grid, I cause a postback (e.g., rebind) or reorder a column, or sort, etc.
- The columns need to be re-added (I've covered a case to exclude the column with the old name)
- Before columns are added again, I manually clear sort expressions on the grid
- While debugging, I found that in the ColumnCreated event, the grid sort expressions restore to what they were before the postback, and I see 'My Column ASC' - I find that whenever adding a SortExpression referencing a non-existing column, the program always breaks
I debugged against a few events of the grid and found that in ColumnCreated (after NeedDataSource) the grid restored its sort expressions from what I presume is the control state. So, this was between NeedDataSource and ColumnCreated.
When exactly did the sort expressions get restored, and is there an event I can listen to?