i has 2 resx files Test1.aspx.resx (for english) Test1.aspx.ko.resx(for korean) its working fine when language has changed on IE settings(that is automatic detection), my question is on my page i has a dropdownlist and showing the languages list, based on
the user selected language i have to display language resx file. by default its automatically working based on the culture and no need to write any new code, but how to do this by user selected language?
hi Ahmed thanks for your response. Its working fine. But, i have to pick the selected language from the Dropdownlist but this method protected override void InitializeCulture() has fired before Page_load event, on the pageload event only we can get the value
from DDL, then how to change the code based on this situation. Please guide me.
thanks for your response. Its working fine. But, i have to pick the selected language from the Dropdownlist but this method protected override void InitializeCulture() has fired before Page_load event, on the pageload event only we can get the value from
DDL, then how to change the code based on this situation. Please guide me.
Okay I try to explain, you don't have to do anything, that why we are using Request.Form["langDropDownList"] instead of ddl.SelectedValue;
When page will load first time if ((Request.Form["langDropDownList"] != null)) will be null so the default culture of user browser as per his preference will set thats what the intention should be.
Next time if user changes the language selection from dropdown list, Request.Form["langDropDownList"] will give you the selected value (it will be available as we are taking it from request object) and code will pick that value and set the culture. so you
don't have to use selectedindex_changed event of dropdownlist. add this ddl in your page and debug.
I have one more doubt, in my aspx page, i has ascx control, when change the language then i have to change that text's also.
by normal way if we have created the resx file for the ascx file and if we selected the language then that too automatically converted or we have to some manual work?
its should work for user control also, I don't remember any thing special needs to be done and honestly I never did that user control, so just give it try and if problems forums.asp.net is here.
winseealn@ho...
Participant
853 Points
1068 Posts
call resx based on language selection
Jul 13, 2010 12:06 PM|LINK
hi all,
i has 2 resx files Test1.aspx.resx (for english) Test1.aspx.ko.resx(for korean) its working fine when language has changed on IE settings(that is automatic detection), my question is on my page i has a dropdownlist and showing the languages list, based on the user selected language i have to display language resx file. by default its automatically working based on the culture and no need to write any new code, but how to do this by user selected language?
SSA
Star
9380 Points
1580 Posts
Re: call resx based on language selection
Jul 13, 2010 01:06 PM|LINK
Just add this function(if no master page): here selectedLanguage value should be like: en-US or en-GB or nl-NL.
protected override void InitializeCulture() { if ((Request.Form["langDropDownList"] != null)) { String selectedLanguage = Request.Form["langDropDownList"]; UICulture = selectedLanguage; Culture = selectedLanguage; Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage); Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage); Session["Language"] = selectedLanguage; } else if (Session["Language"] != null) { String selectedLanguage = Session["Language"].ToString(); UICulture = selectedLanguage; Culture = selectedLanguage; Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage); Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage); } base.InitializeCulture(); }nareshguree2...
Star
11118 Points
1997 Posts
Re: call resx based on language selection
Jul 13, 2010 01:12 PM|LINK
try this
http://social.msdn.microsoft.com/forums/en-US/clr/thread/c86ef2ba-77d0-4a90-8a54-624e72d87a61
http://forums.asp.net/t/905857.aspx
Ahmed Moosa
Star
7784 Points
1232 Posts
Re: call resx based on language selection
Jul 13, 2010 01:19 PM|LINK
using System.Globalization; using System.Threading; public partial class _Default : System.Web.UI.Page { protected override void InitializeCulture() { string Language = Request.Form["DropLang"]; if (Language != null ) { Thread.CurrentThread.CurrentUICulture = new CultureInfo(Language); Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Language); } } }you can put it Base Class , after that all page can inhert it .
MCC - MCPD -MCTS
anup_daware
Contributor
3166 Points
560 Posts
Re: call resx based on language selection
Jul 14, 2010 03:20 AM|LINK
Hi,
This post talks about exactly what you are trying to find:
http://forums.asp.net/p/1288742/2483993.aspx#2483993
Thanks,
Anup
winseealn@ho...
Participant
853 Points
1068 Posts
Re: call resx based on language selection
Jul 14, 2010 06:55 AM|LINK
hi Ahmed thanks for your response. Its working fine. But, i have to pick the selected language from the Dropdownlist but this method protected override void InitializeCulture() has fired before Page_load event, on the pageload event only we can get the value from DDL, then how to change the code based on this situation. Please guide me.
winseealn@ho...
Participant
853 Points
1068 Posts
Re: call resx based on language selection
Jul 14, 2010 06:57 AM|LINK
Hi SSA.
thanks for your response. Its working fine. But, i have to pick the selected language from the Dropdownlist but this method protected override void InitializeCulture() has fired before Page_load event, on the pageload event only we can get the value from DDL, then how to change the code based on this situation. Please guide me.
SSA
Star
9380 Points
1580 Posts
Re: call resx based on language selection
Jul 14, 2010 08:43 AM|LINK
Okay I try to explain, you don't have to do anything, that why we are using Request.Form["langDropDownList"] instead of ddl.SelectedValue;
When page will load first time if ((Request.Form["langDropDownList"] != null)) will be null so the default culture of user browser as per his preference will set thats what the intention should be.
Next time if user changes the language selection from dropdown list, Request.Form["langDropDownList"] will give you the selected value (it will be available as we are taking it from request object) and code will pick that value and set the culture. so you don't have to use selectedindex_changed event of dropdownlist. add this ddl in your page and debug.
winseealn@ho...
Participant
853 Points
1068 Posts
Re: call resx based on language selection
Jul 14, 2010 10:23 AM|LINK
SSA, its a good shot.
I have one more doubt, in my aspx page, i has ascx control, when change the language then i have to change that text's also.
by normal way if we have created the resx file for the ascx file and if we selected the language then that too automatically converted or we have to some manual work?
SSA
Star
9380 Points
1580 Posts
Re: call resx based on language selection
Jul 14, 2010 11:38 AM|LINK
its should work for user control also, I don't remember any thing special needs to be done and honestly I never did that user control, so just give it try and if problems forums.asp.net is here.