asp.net - How can access sublayout control from another sublayout in Sitecore? -


i have master layout , 3 sublayout header, content, footer. in header sublayout have search textbox , search button, on click of search button result display on content sublayout, on content sublayout have repeater not able access repeater control in header sublayout.

enter image description here

i've dealt similar problems in sitecore sites before. there 2 ways of doing i'd suggest consider:

1) custom code, layout can act intermediary sublayouts

define sort of "receive results" interface can implemented sublayout wants handle search results. example:

interface irendersearchresults {    void renderresults(ienumerable<searchresultdata> resultset); } 

make "content" sublayout implement interface, when sends search results, can handle them:

public class contentsublayout : sublayout, irendersearchresults {   public void renderresults(ienumerable<searchresultdata> resultset)   {      repeatercontrol.datasource = resultset;      // whatever other data binding tasks required   } } 

then extend layout have methods "register me receive search results" , "send search results wherever they're needed":

public class mylayout : page {   private list<irendersearchresults> resultcontrols = new list<irendersearchresults>();    public void registersearchresultscontrol(irendersearchresults control)   {     resultcontrols.add(control);   }    public void dispatchsearchresults(ienumerable<searchresultdata> resultset)   {      foreach(var control in resultcontrols)      {         control.renderresults(resultset);      }   } } 

your "content" control should register when it's created, calling register method on layout. add method like:

protected void page_init(object sender, eventargs e) {   mylayout layout = (mylayout)this.page;   layout.registersearchresultscontrol(this); } 

finally, when header control has generated results display, should dispatch them call layout:

public class myheader : sublayout {   public void dothesearch()   {     // whatever perform search      mylayout layout = (mylayout)this.page;         layout.dispatchsearchresults(thesearchresults);   } } 

(this code typed off top of head, rather copy/pasted - there may typos - sorry)

that way set of results receiving controls can exist anywhere on page (and can added / removed via page editor if want) whenever search run, if they're on page results. approach can allow make things paging ui results, or results summary display separate controls editors can move around page.

note if have multiple layouts on site, need make sure dispatching code in base class of layouts, make sure it's available if editor changes layout of particular page.

2) use sitecore's event model article gives helpful description of how internal framework events works: https://adeneys.wordpress.com/2012/10/21/decoupling-through-the-sitecore-event-pool/ there others if google.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -