SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi I have some code that modifies the connected view of a XsltListViewWebPart.

This bit works find I can update the query and the list is filtered appropriately, however it takes a refresh of the page to show the changes. So currently: Filters are set by user and button clicked Postback sets the view appropriately Page is loaded and old view is shown, hit Post back again to load the page and the list shows the correct data.

Code currently is:

this.web.AllowUnsafeUpdates = true;
XsltListViewWebPart listView = null;
using (SPLimitedWebPartManager wpm = web.GetLimitedWebPartManager(this.Page.Request.Url.AbsolutePath, PersonalizationScope.Shared))
    foreach (System.Web.UI.WebControls.WebParts.WebPart current in wpm.WebParts)
        if (current is XsltListViewWebPart)
            listView = current as XsltListViewWebPart;
            SPList list = web.Lists[new Guid(listView.ListName)];
            SPView view = list.Views[new Guid(listView.ViewGuid)];

            if (clauses != null && clauses.Count > 0)
                view.Query = clauses.BuildQuery();
                view.Query = string.Empty;

            listView.XmlDefinition = view.GetViewXml();

            this.fields.Value = this.GetFields(list);
            this.operators.Value = string.Join(",", this.operatorList);

            if (HttpContext.Current.Items["transfer"] != null)
                 HttpContext.Current.Server.Transfer(this.Page.Request.Url.AbsolutePath, true);

The clauses.BuildQuery just returns a Where XML clause. Other code in here such as databind, forcedatabind save etc have not worked. Even trying to use Server.Transfer to effectivley force a refresh does not work.

Any ideas?

share|improve this question

try using :

share|improve this answer

a - not so nice but working - workaround is doing a redirect with code like this:


I'm searching for a better solution...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.