0

I want to change language with LinkButton in my project

 <asp:LinkButton ID="LinkButton1" runat="server"            
PostBackUrl="~/mypage.aspx?lang=en">english</asp:LinkButton>


<asp:LinkButton ID="LinkButton2" runat="server" 
PostBackUrl="~/mypage.aspx?lang=ru">русский</asp:LinkButton>

For this page I created local resources

mypage.aspx.resx

mypage.aspx.ru.resx

when I press this linkbutton nothing happens

Alex
  • 8,908
  • 28
  • 103
  • 157
  • what is your code behind doing when it evaluates the "lang" query string parameter? I don't think it will work out of the box – Raphael Gabbarelli Aug 01 '12 at 07:43
  • @ Raphael Gabbarelli when I write in the address bar "mypage.aspx?lang=ru" the page is translated into Russian – Alex Aug 01 '12 at 07:50

1 Answers1

3

try to add this code to your Page_Load event (it will be more effective if you use a base class for your pages, and put this code into that base page, so that all pages in the application will be able to switch language)

if(Request.QueryString["lang"] == "en")
{
    var english = new CultureInfo("en");
    System.Threading.Thread.CurrentThread.CurrentCulture = english;
    System.Threading.Thread.CurrentThread.CurrentUICulture = english;
}
else if(Request.QueryString["lang"] == "ru")
{
    var russian = new CultureInfo("ru");
    System.Threading.Thread.CurrentThread.CurrentCulture = russian;
    System.Threading.Thread.CurrentThread.CurrentUICulture = russian;
}

Be aware that also date formats as well as number (and currency) formats will change accordingly, if you don't force the format.

  • I added this code to my Page_Load but how to change querystring["lang"] to en or ru if my LinkButton doesn't work – Alex Aug 01 '12 at 08:17
  • for test purpose, I added 2 links similar to the 2 you used, using PostBackUrl, and they work properly. Can you try to see if the link buttons have some event handlers attached to them? this might prevent the main event to work correctly. are you using some AJAX? – Raphael Gabbarelli Aug 01 '12 at 08:22