0

I'm implementing search center in server side(c#) with ResultScriptWebPart class in sp2013 farm. it a dynamic page with control template and item template that are changing on the fly depending on the query string.

It all work well except in the first time when the templates need to change - then I notice I am receiving the previous templates,after I refresh I get the wanted result. How can I fix this situation that my result will load at first time. thank you

 private void EnhanceQuery(object sender, ScriptWebPart.BeforeSerializeToClientEventArgs e)
    {

        RenderClientScript();
        string itemTemplateID = "";
        string query = "";
        string controlTemplate = "";
        if (String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["equery1"]) == false)
        {
            query = "equery1={QueryString.query1} AND equery2={QueryString.equery2} AND equery3={QueryString.equery3} ContentSource:Clalit_SeferSherutEmp";
            itemTemplateID = "path.js";
            itemTemplateID = "path1.js";
            controlTemplate = "controlpath1.js";
        }
        else if (String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["query4"]) == false)
        {
            query = "query4:{QueryString.query4}   ContentSource:Clalit_SeferSherutDept";
            itemTemplateID = "itemPath2.js";
            controlTemplate = "controlpath1.js";
        }
        else if (String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["query5"]) == false)
        {
            query = "query5={QueryString.query5}  ContentSource:csMedicine";
            itemTemplateID = "itemPath3.js";
            controlTemplate = "controlPath2.js";
        }

        this.PreloadedItemTemplateIdsJson = "[\"customScript.js\","+

        "\"~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default.js\", " +
        "\"~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Site.js\", " +
        "\"~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Word.js\", " +
        "\"~sitecollection/_catalogs/masterpage/Display Templates/Search/item_word_hoverpanel.js\", " +
        "\"~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_PowerPoint.js\", " +
        "\"~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Person_CompactHorizontal.js\", " +
        "\"~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_BestBet.js\", " +
        "\"~sitecollection/_catalogs/masterpage/Display Templates/Search/control_searchresults.js\", " +
        "\"~sitecollection/_catalogs/masterpage/Display Templates/Search/group_default.js\", " +
        "\"~sitecollection/_catalogs/masterpage/Display Templates/Search/item_commonitem_body.js\", " +
        "\"~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_WebPage.js\"]";
        this.MaxPagesBeforeCurrent = 4;
        this.ScrollToTopOnRedraw = false;

      //  this.SelectedPropertiesJson = selectedProperties;

        this.RepositionLanguageDropDown = false;

        this.ResultsPerPage = 10;
        this.EmitStyleReference = true;

        this.AllowMinimize = true;
        this.AllowClose = true;
        this.Title = "תוצאות חיפוש";

        this.MaxPagesAfterCurrent = 1;

        this.Hidden = false;
        this.UseSimplifiedQueryBuilder = false;
        this.HitHighlightedPropertiesJson = "[\"Title\",\"Path\",\"Author\",\"SectionNames\",\"SiteDescription\"]";
        this.AvailableSortsJson = "[{\"name\":\"רלוונטיות\",\"sorts\":[]},{\"name\":\"תאריך (החדש ביותר)\",\"sorts\":[{\"p\":\"Write\",\"d\":1}]},{\"name\":\"תאריך (הישן ביותר)\",\"sorts\":[{\"p\":\"Write\",\"d\":0}]},{\"name\":\"תצוגות של משך חיים\",\"sorts\":[{\"p\":\"ViewsLifeTime\",\"d\":1}]},{\"name\":\"תצוגות אחרונות\",\"sorts\":[{\"p\":\"ViewsRecent\",\"d\":1}]}]";
        this.AllowHide = true;
        this.AllowEdit = true;
        this.StatesJson = "{}";

        this.AllowConnect = true;
        this.Description = "הצגת תוצאות החיפוש והמאפיינים המשויכים אליהן.";
        this.ServerIncludeScriptsJson = "null";
       // this.EmptyMessage = "משה אתה לא קיפוד";
        //this.AlternateErrorMessage = "oops ronen did it again";
        this.ShowResults = true;
        this.ShowResultCount = true;
        this.ShowDefinitions = false;
        this.ShowLanguageOptions = false;
        this.ShowAlertMe = false;
        this.ShowDidYouMean = false;
        this.ShowAdvancedLink = false;
        this.ShowViewDuplicates = false;
        this.ShowPersonalFavorites = false;
        this.ShowSortOptions = false;
        this.ShowViewDuplicates = false;
        this.ShowPaging = false;
        this.ShowUpScopeMessage = false;
        this.ShowPreferencesLink = false;

        this.ChromeType = PartChromeType.None;
        this.ChromeState = PartChromeState.Normal;
        this.QueryGroupName = "Default";
        this.ActiveDataProvider.SourceID = null;
        this.ActiveDataProvider.SourceName = null;




        DataProviderScriptWebPart querySettings = new DataProviderScriptWebPart
        {
            PropertiesJson = this.DataProviderJSON
        };

        querySettings.Properties["QueryTemplate"] = query.ToString();
        this.DataProviderJSON = querySettings.PropertiesJson;
        this.BypassResultTypes = true;


        //if (SPContext.Current.Web.DoesUserHavePermissions(SPBasePermissions.UpdatePersonalWebParts))
        this.RenderTemplateId = controlTemplate;
        this.ItemTemplateId = itemTemplateID;

        this.SaveProperties = true;
1
  • This sounds like a browser caching issue. – A.k.A. Fritz Jan 22 '20 at 0:47
0

Ohh, well , the answer is :

this.ViewStateMode = ViewStateMode.Disabled;

feel sheepish

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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