Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Detect culture change? View modes: 
User avatar
Member
Member
james-agencynet - 2/10/2012 1:41:14 PM
   
Detect culture change?
Hello, is there any kind of listener or notifier that i can listen on that would notify a webpart when the user changes to a different culture?

Thanks.

User avatar
Member
Member
kentico_michal - 2/12/2012 5:24:59 AM
   
RE:Detect culture change?
Hello,

Regrettably, there is no handler available in the current version of Kentico CMS.

You can, however, store the current culture the the session and each time the page is posted back to the server check whether the culture has been changed by comparing the current culture with the one retrieved from the session. The code could look like the following one:

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
bool changed = false;

string previousCulture = ValidationHelper.GetString( SessionHelper.GetValue("culture"), String.Empty);
string currentCulture = CMSContext.CurrentDocument.DocumentCulture;

if (previousCulture != String.Empty)
{
if (previousCulture != currentCulture)
{
changed = true;
}
}
SessionHelper.SetValue("culture", currentCulture);

if (changed)
{
// do something
}
}


Best regards,
Michal Legen