Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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();
            }
            else
            {
                view.Query = string.Empty;
            }
            listView.Dispose();
            view.Update();

            listView.XmlDefinition = view.GetViewXml();
            listView.ForceDataBind();
            listView.DataBind();
            wpm.SaveChanges(listView);

            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
add comment

2 Answers

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

this.Context.Response.Redirect(this.Context.Request.Url.ToString());

I'm searching for a better solution...

share|improve this answer
add comment

try using :

listView.PartCacheInvalidate();
share|improve this answer
add comment

Your Answer

 
discard

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.