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.
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,
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.
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?