LinkButton PostBack Language Problem

Vote:
 

Hi Episerver,

I'm having a problem where I'm using a LinkButton asp.net control which does a Postback from one language but returns the page back in another.

For example, if I'm on http://mysite.com/de/page and I do a postback on the page with a link button, I will return back to http://mysite.com/en/page instead of the German page I was expecting. I've tried using UserInterfaceLanguage.Instance and ContentLanguage.Instance to set the correct language on PreInit but none of these have the desired effect.

Can anyone help out?

Kind Regards,

Chris

#21723
Jul 07, 2008 12:36
Vote:
 

Hi!

This is a little bit tricky but not impossible.

The problem is related to LinkUrl, which I guess you use. It does not look at the its own PageData.LanguageBranch property to calculate the URL. Instead it will use ContentLanguage.PreferredCulture for some strange reason.

//LinkURL uses PreferredCulture to calculate it's value and we have to change it manually before reading it.
currentPreferredCulture = ContentLanguage.PreferredCulture;
if (string.Compare(page.LanguageBranch, ContentLanguage.PreferredCulture.Name, StringComparison.OrdinalIgnoreCase) != 0)
{
ContentLanguage.PreferredCulture = CultureInfo.GetCultureInfo(page.LanguageBranch);
}
YourLink.NavigateUrl = page.LinkURL;
ContentLanguage.PreferredCulture = currentPredderedCulture;

Another way to do it is to add the language yourself. This looks easier but has side effects because it does not consider you settings in the siteHosts tag.

UriSupport.AddLanguageSelection(page.StaticLinkUrl, page.LanguageBranch);

/Fredrik

#21725
Jul 07, 2008 13:57
Vote:
 

I think this might be useful for something else actually, however I'm just using a OnClick event for the LinkButton control so there's no LinkUrls being used. I've tried setting the preferred language on the Click event and on page preinit but this still changes the URL from de to en.

As mentioned before, the LinkURL trick above will be useful so thank you for sharing that,

Chris

#21733
Jul 07, 2008 15:02
Vote:
 

Ah, I just found out my problem. The Form action for the /de/page was set to point to /en/page. This was because I have Language Fallback on. So I was trying to go to a page which hadn't been created yet, so it was falling back to the default language page which had been created.

Thanks Fredrik for the help, I'm sure I will be using that code in the future.

Chris

#21734
Jul 07, 2008 16:01