I have a drop down list with the different languages the website supports. I tried to change the culture based on the _selectedIndexChanged event. But that doesn't work since the page_load event is called before the index change event.
in other words- in the page_load event the Thread.CurrentThread.CurrentCulture is set to "en-US".
When s/o selects a value in the drop down list , the pageload is called and only then is the selectedIndexChanged called and sets the current culture to "fr-FR". the page does not show the change because the pageload event happened already!!
What exactly am I doing wrong??????????
Anh Duc ThaiPosted Jan 14, 2008, 8:48 PM
Instead of letting the .NET made a postback, you can implement postback for your language dropdownlist. All you need to do is to create a Javascript function, something like this:
function languageChanged(me)
{
if(me == null)
return;// Nothing happens.
__doPostBack("LANGUAGE_INDEX_CHANGED", me.selectedIndex);
}
On the server code, you must assign: this.languageDropdownList.Attributes["onchange"] = "languageChanged(this);"
On Page_Load, you must check if the postback was striggered by language dropdownlist.
if(Request["__EVENTTARGET"] == "LANGUAGE_INDEX_CHANGED")
{
/// Get the selected index of language dropdownlist.
int index = Convert.ToInt32(Reguest["__EVENTARGUMENT"]);
/// Initialize the cuture here.
}
// Note: You shoud disable auto postback of dropdown list.
Hope it will help you.
ArshadPosted Jan 14, 2008, 2:14 PM
Just write Your Thread in to the Class,dont write any thing in to the Page_Load
public class WebForm1 : System.Web.UI.Page
{
}
After that you write ur SelectedIndexChange Event,and write ur code in to the Event.r u doing like that?????
kailaPosted Jan 14, 2008, 1:44 PM
It is refreshing the page, but the page_load comes before the selected index, so the change is not made.
ArshadPosted Jan 14, 2008, 1:41 PM
Then check ur selectedIndexChanged Event,or ur Event Handler.
Without seeing the code i cant Help you.Thanks
Regards
Arshad Khan
kailaPosted Jan 14, 2008, 1:36 PM
ArshadPosted Jan 14, 2008, 1:34 PM
Then what problem you are getting?????????
Is it giving any Error???????
kailaPosted Jan 14, 2008, 1:27 PM
yes I have resource files for both languages.
ArshadPosted Jan 14, 2008, 1:20 PM
Hi,you just try to right ur Thread in to the selectedIndexChanged of DropDown.ok,and b4r going for Globalization first u will have to create ur Resource file in the ASP.NET application.ok,i hope ur doing like that only.
Thanks
Regards
Arshad Khan