开发者

Changing context element dynamically regarding some condition in Sitecore CMS

I have user control under Sitecore CMS. It has some controls bound to some fields o开发者_高级运维f context. For example:

<sc:text runat="server" field="HomePage_WelcomeText"></sc:text>

I have different content items based on the same template and I need to change context to some of them in PageLoad(). For example, if URLRefferer has certain value I want to have certain content item in context.

Any hints?


The sc:text control has a public property called Item that takes a Sitecore.Data.Items.Item. So, give your control an ID attribute, then on Page_Load you can dynamically set that Item property as needed.

<sc:text id="myTextControl" runat="server" field="HomePage_WelcomeText" />
protected void Page_Load(object sender, EventArgs e)
{
    Sitecore.Data.Items.Item myItem = Sitecore.Context.Database.GetItem("/sitecore/content/home");
    myTextControl.Item = myItem;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜