How to preserve Sharepoint view filter on postback programmatically
I have a Sharepoint 2007 document library. There is a custom action associated with a document menu (when you click on the drop down list of a given document). When the user clicks that menu, some custom code gets executed. However, after the custom code executes, the page reloads and shows the document library in its default view. I want the users to be able to define their own views and then when the custom code executes, I want the view to stay exactly the same instead of reverting back to the Default View. I'm guessing that at the beginning of the custom code I need to somehow retrieve the current view filter and then after the code executes I need to set the lists' view to be that view again. I've found the code for retrieving the list view filter by GUID (list.GetView(GUID) but I want to be able to retrieve the current view. Or is there some other way to specify for the view to stay the same? The view stays the same when the Sharepoint native code executes and refreshes the page so this problem only occurs with the custom code. thanks,
July 24th, 2012 10:21am

Hi, You can execute the following code to get the view Id from current view SPContext.Current.ViewContext.ViewId If you want to get the SPView object you can use this code instead. SPContext.Current.ViewContext.View I hope this will help you out.Thanks, Rahul Rashu
Free Windows Admin Tool Kit Click here and download it now
July 24th, 2012 3:31pm

To maintain the same view as present before your custom code you need to get the all the parameters present in the Query String like View, Sort Field etc. all the parameters for filtering and sorting. Once you completed your custom code you can redirect to the same page with the Query String parameters that you have saved in the start. Because SharePoint handles filtering, sorting and paging through Query String. Hope this will help.Sharepoint Sutra Sharepoint Consultant
August 12th, 2012 9:17pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics