Archive for the ‘ajax’ Category

Enable AJAX history in SharePoint Webpart pages

July 17, 2009

The problem:
You want to enable the back button in browser for the actions that are done through Ajax calls. It is pretty simple in a normal .NET 3.5 aspx web app. You can find the quidance here.

However this guidance did not work for me in a SharePoint webpart page. The history points in the back button browser history worked fine, the problem occured when I actually clicked the back button. The page changed back to the previous page  and then came back to the original page. After some fiddling I found out that this is because the __eventtarget parameter in the history page request is wrong. The parameter was set on the button and not on the scriptmanager as it should be. Therefore the button event click was fired when the history page wass loaded and then the original page was loaded again

The solution:
Create a new custom web part page. See Ted Pattison guide how to create a custom web part page. When done modify it and add a ScriptManager directly into the aspx code of the web part page. From now the browser history should work correctly.

When I used the Publishing page I did not come across this problem. Why? Did not have time to find out. 🙂

This feels rather like a workaround, if anybody ever reads this blog and has a better solution please let me know.