How to get value from control placed in master page when using ASPX templates

   —   
This article describes how to get value from control placed in master page on some other ASPX template when using ASPX templates development model.
You can use CMS.Controls.CMSControlsHelper.SetFilter method in your master page to set the control to RequestStockHelper (you can find sample code for this method in SetupControl method of ~\CMSWebParts\Viewers\BasicRepeater.ascx.cs file) and then in your aspx template you can use CMS.Controls.CMSControlsHelper.GetFilter method to get the control from RequestStockHelper. Please see example bellow:

1) put following code into master page:
<asp:Literal ID="litCurrentSection" runat="server" Visible="false"></asp:Literal>

2) put following code into page_load method of master page:
litCurrentSection.Text = "Test";
CMS.Controls.CMSControlsHelper.SetFilter("litCurrentSectionTest", litCurrentSection);


3) Put following code into Page_Load method of your aspx template:
Literal testLiteral = CMSControlsHelper.GetFilter("litCurrentSectionTest") as Literal;

and check value of its Text property. It should contain "Test".


See also:

Applies to: Kentico CMS 4.0 or newer.
Share this article on   LinkedIn Google+