SPGridView and control with specified ID could not be found error
Today I was working on creating some custom SharePoint application pages that utilized the SPGridView to display data from a list I had in SharePoint. I used Powlo's blog post on SPGridViews as a starting point. I set up my GridView and attached it to my data source (SharePoint List) and was excited to see how easy it was to bind the data.
The next thing I wanted to do was filter the data in the SPGridView to only display items created by the current user. I found this post that explained how to build a select command using CAML that would filter down the data. This is exactly what I wanted.
So the next logical step in my journey was to allow the user to filter on different criteria and then filter the SPGridView and then re-display the data. I added a button to cause the page to post back and refresh the data in the GridView. I tested it out and my filter worked fine, THE FIRST TIME. The minute I went to click on the button after the initial post back, I got an ugly error -
"A control with the specified ID 'SubmittedListMenu' could not be found within the scope of the current naming container. ..." and it continued into the method calls.
I looked on the net for anything that looked similar to this error and found one post about issues with post backs and the SPGridView control. This did not help me out, but it got me thinking that the issue was probably in the fact taht data rows were available before that postback that would not be after the postback. So I went into the properties for the SPGridView and set the EnableViewState to false. I then went back to the page and tried it. This time since I was not tryint to keep track of the child controls in the GridView, I could keep hitting the submit button without any problems. As long as you don't need the ViewState enabled on that control, this is an easy solution to a problem that was not so easy to figure out.
Chalk up another afternoon to SharePoint debugging.
Labels: postback error, SPGridView, SPGridView and Postback error
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home