2

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?

2 Answers 2

2

try using :

listView.PartCacheInvalidate();
0

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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.