SharePoint’s Data Form Web Part, Edit Mode, and “Id” Query Parameter
So a few days ago, I stumbled upon a baffling bug in SharePoint while using a data form web part to allow for editing a list item in a custom list. In the past, whenever I’ve created custom data form web part pages for editing, I’ve always followed SharePoint’s schema of using the “Id” query parameter to indicate which list item is being editted. In this case, I was already using “Id” in another web part on the same page, so I just modified my data form web part to use some other query parameter, like “ItemId”. Simple, right?
As soon as I set that up and went to test, I got an error: “No item exists at <url>. It may have been deleted or renamed by another user.”
What the heck? I verified I was using the right ItemId, and double-checked that my Id that the other web part on the page was using was correct as well. My Ids were perfectly valid, so what’s going on? Through some troubleshooting, I discovered that it was a combination of the “Id” parameter and my edit data form web part. Even removing everything else on the page so there was nothing using the “Id” parameter still resulted in an issue if both parameters were present in the url.
Switching my edit data form web part to use “Id” instead of “ItemId” fixed the issue at hand, but it still caused problems because I had other things on the page that required the “Id” parameter. I also found during testing that if I supplied “Id” with a valid item id, the edit data form web part would work again despite it never referencing the “Id” parameter – but as soon as that Id was set to an id that didn’t exist, it blew up again.
It turns out that the edit (and I suspect, new) data form web part is still, somewhere along the lines, using Id and it gets confused if you supply your own Id parameter. There’s even a KB article about it: http://support.microsoft.com/kb/972225. The fix/workaround is to just never use “Id” on a page with an edit/new data form web part, unless of course “Id” is what your edit/new data form web part is explicitly using (that still works – so baffling!). I adjusted my other web parts on the page to use something different so “Id” wouldn’t be a required parameter, and all issues disappeared.