Last post May 07, 2011 04:48 AM by sjnaughton
May 06, 2011 01:58 AM|borutsla|LINK
I had problems with my custom field generator. If I put this line of code
GridView1.ColumnsGenerator = new FieldGenerator(table, true);
in page_init event, I get no errors, but event GenerateFields never fires.
Then I found answer on this forum, that I have to move this line of code to Page_Load event, but now I ger this error, when I am selecting rows in gridview.
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
May 06, 2011 04:36 AM|asheejtk|LINK
Have a look at below article for the reason and resolution with detailed explanation,
May 06, 2011 05:39 AM|borutsla|LINK
I don't think this is the answer I was looking for.
In my case, if I comment line, or move it to Page_Init event
everything works ok.
May 06, 2011 06:10 AM|sjnaughton|LINK
Hi borutsla, are you using VS2010 and .Net 4? if so have a look at my article here
A New Way To Do Column Generation in Dynamic Data 4 this gets around having to add a fiedl generator to each page but doing it inside a cusom MetaModel
May 06, 2011 09:06 AM|olegsych|LINK
This might be a result of having the GridView in a user control. Depending on where in the page lifecycle the user control is initialized, Page.Init event may have already fired and the Page_Init handler of the user control will not be called. I would stay
away from the Page event handlers and try using Control events instead. For example, assigning the columns generator in the GridView.Init event handler is guaranteed to fire because Control.Init method is invoked as part of the "catch-up" process even if the
control is added to the page late in the life-cycle. GridView.Init event is also a better place to do this because Page.Init event fires after Control.Init events and the view state tracking has already been turned on for the GridView, which will lead to errors
May 07, 2011 04:48 AM|sjnaughton|LINK
Hi Oleg, see this thread where David Ebbo has the answer