问题描述
我有一个很难在Sitecore的7号楼过滤系统。
I'm having a hard time building a filtering system in Sitecore 7.
我有2 sublayouts,在页面的相同的水平。
I have 2 sublayouts, on the same level of the page.
Sublayout一个是包含复选框的列表,并有填充与所选值的列表事件的侧边栏。
Sublayout乙会显示一组项目。
Sublayout A is a sidebar that contains a list of checkboxes and has an event that populates a List with the selected values.Sublayout B displays a set of items.
我想什么做的,是从一个sublayout发送填充的列表来sublayout B的顺序进行过滤基于用户选择什么项目列表。
我能够通过将数据通过会话要做到这一点,但这并不是处理这些数据的最佳方式。
What I would like to do, is send the populated List from sublayout A to sublayout B in order to filter the items list based on what the user selected.I was able to do this by passing the data through Session, but this is not an optimal way of handling that data.
我试着定义sublayout一个属性,并加载列表出现,但为了阅读填充属性我无法从sublayout乙得到sublayout A的确切实例。
此外,试图Page.FindControl(IdOfSomeElementFromSublayoutA)总是Sublayout B.返回null即使我已经铸成页面作为包含Sublayouts .aspx页。
I've tried defining a property for sublayout A and loading the list there, but I can't get the exact instance of sublayout A from sublayout B in order to read the populated property.Also, trying to Page.FindControl("IdOfSomeElementFromSublayoutA") always returns null in Sublayout B. Even though I've casted Page as the .aspx page that contains both Sublayouts.
我使用Sitecore的7更新2
I'm using Sitecore 7 Update 2.
非常感谢您的时间。
推荐答案
要做到这一点,最好的办法是通过提高(和订阅)使用事件 Sitecore.Events.Event
类。您的侧边栏sublayout会使用类似按钮的Click事件处理程序中的以下触发事件:
The best way to do this is by raising (and subscribing to) events using the Sitecore.Events.Event
class. Your sidebar sublayout would raise an event using something like the following within a button's click event handler:
Sitecore.Events.Event.RaiseEvent("YourEventName", new YourEventArgsClass { Property = "SomeValue" });
然后在其他sublayout,你需要有为了处理事件的以下设置:
then in the other sublayout you would need to have the following set up in order to handle the event:
public partial class YourOtherSublayout : System.Web.UI.UserControl
{
private System.EventHandler eventHandlerRef;
protected void Page_Load(object sender, EventArgs e)
{
eventHandlerRef = EventHandlerMethod;
Sitecore.Events.Event.Subscribe("YourEventName", eventHandlerRef);
}
protected void Page_Unload(object sender, EventArgs e)
{
if (eventHandlerRef != null)
{
Sitecore.Events.Event.Unsubscribe("YourEventName", eventHandlerRef);
}
}
private void EventHandlerMethod(object sender, EventArgs e)
{
if (e != null)
{
//do stuff here
}
}
}
注:重要的是要保持激发Page_Unload code有,否则你将看到被多次调用该事件处理方法
Note: it is important to keep the Page_Unload code there otherwise you will see the EventHandler method being called multiple times.
这篇关于在Sitecore的发送从一个sublayout数据到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!