dynamic GridView in CreateChildControls throws a "RegisterRequiresControlState can only be called be

Posted by tbischel on Stack Overflow See other posts from Stack Overflow or by tbischel
Published on 2010-05-11T22:33:43Z Indexed on 2010/05/11 23:24 UTC
Read the original article Hit count: 991

Filed under:
|
|
|

I am trying to add a GridView dynamically to a SharePoint Web Part. Right now, the first time I load the gridview, everything works fine. My gridview has an edit column enabled... so when I click that, it throws an exception when I try and add the gridview control on the postback.

The exception: "RegisterRequiresControlState can only be called before and during PreRender"

I've tried adding my controls in the CreateChildControls function, the OnInit, OnPageLoad, and OnPreRender... all exhibit the same problem.

Does anyone know what might cause this kind of error?


Edit:

So to test this problem, I created a local GridView in the webpart, recreating all the properties in the one that failed. It actually worked this time through... the only difference that I could identify was that I had made the gridview a static variable in another class, where as here I initiated the gridview as a local variable. I even used the same initializing function for both the original and modified version, same difference. So why would creating a GridView locally affect the ability to add it to a web part?

© Stack Overflow or respective owner

Related posts about sharepoint2007

Related posts about c#