Hi,
I have created the .ascx controls in visual studio.
Now, I want to give the users to select language option.
How can I achieve this feature in same controle through coding.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
mihir soni41 reputationPosted May 9, 2010, 9:26 PM EDT
Keyur Shah5 reputationPosted May 9, 2010, 9:35 PM EDT
I have some webpages which are ".ascx" controls.
Those webpages are displayed currently in "EN-US' language.
Now, what I want is that user can select the language in which the webpage should appear.
I have tried changing the language in [Internet option->Language] but it doesnot work.
I have also seen the many blogs which are telling about resolution file ".resx", But this will be very
tidious job, as I ahve So many pages to be convert.And also It won't convert the data displayed on the webforms.
What I want is that by any chace on page Load we can define the datasource language and webpage language
through codes.Than that will be useful for me.
Thnks For Reply.
Regards,
Keyur Shah
mihir soni41 reputationPosted May 10, 2010, 9:42 PM EDT
Hello,
If you are creating multilingual application then based on query string or session set value in Basepage. I have created one sample for you. One more thing date respective and currency respective it will handle automatically. But one thing you have to take care while display currency it will display in with "comma" but you have to take care when you enter into database then 1,00 will not accept by database due to may be you sql is en-Us format then in this case you have to explicitly transalte curency into 1.00. So it will work proper but if you will not take care then this amount will throw exception or will become 1000.00 in database. Just take care such thing rest of thing is fine.
protected override void InitializeCulture()
Based on our requirement we have set greek Based on our requirement we have set greek
{
// Based on Query string we set culture, else we set in web.congig as default country and language code
//
//
if (Request.QueryString.Count > 0)
{
if (Request.QueryString["lang"] != null)
{
pLanguegeCode = Convert.ToString(Request.QueryString["lang"]);
}
else
{
if (ConfigurationManager.AppSettings["DefaultLanguageCode"] != null)
{
pLanguegeCode = Convert.ToString(ConfigurationManager.AppSettings["DefaultLanguageCode"]);
}
}
}
if (ConfigurationManager.AppSettings["DefaultCountryCode"] != null)
{
pCountryCode = Convert.ToString(ConfigurationManager.AppSettings["DefaultCountryCode"]);
}
// based on language code we are setting Culture name
if (pLanguegeCode.ToLower() == "en")
{
Session["CultureName"] = "en-GB";
}
else if (pLanguegeCode.ToLower() == "el")
{
Session["CultureName"] = "el-GR";
}
else
{
Session["CultureName"] = "en-US";
}
if (Session["CultureName"] != null)
{
string cultureName = Session["CultureName"].ToString();
//Change language setting to user-chosen one
if (cultureName != null)
{
//Set Culture
CultureInfo objCultureInfo = new CultureInfo(cultureName);
Thread.CurrentThread.CurrentUICulture = objCultureInfo;
//Set Date Format as per your need
DateTimeFormatInfo objDateTimeFormatInfo = objCultureInfo.DateTimeFormat;
objDateTimeFormatInfo.ShortDatePattern = SetDateFormat();
//In web.config we set default date seprator, you can use . or \
//
objDateTimeFormatInfo.DateSeparator = ConfigurationManager.AppSettings["DateSeparator"].ToString();
objCultureInfo.DateTimeFormat = objDateTimeFormatInfo;
// Here specific culture will set
Thread.CurrentThread.CurrentCulture = objCultureInfo;
if (objDateTimeFormatInfo != null)
objDateTimeFormatInfo = null;
if (objCultureInfo != null) objCultureInfo = null;
}
}
base.InitializeCulture();
}
public string SetDateFormat()
{
string strFormat = "";
//
if (ConfigurationManager.AppSettings["DateFormat"] == null)
{
if (ConfigurationManager.AppSettings["DateSeparator"] == null)
{
strFormat = "MM/dd/yyyy";
}
else
{
//In web.config we set default date seprator, you can use . or \
//
strFormat = "MM" + Convert.ToString(ConfigurationManager.AppSettings["DateSeparator"]) + "dd" + Convert.ToString(ConfigurationManager.AppSettings["DateSeparator"]) + "yyyy";
}
}
else
{
//Based on culture it will set
strFormat = ConfigurationManager.AppSettings["DateFormat"].ToString(System.Globalization.CultureInfo.CurrentCulture);
}
return strFormat;
}
Keyur Shah5 reputationPosted May 10, 2010, 10:11 PM EDT
thanks for ur reply.
Can U please tell me which assembly refrence should be add on top to write this
InitializeCulture() method.
Since, After adding this my page is nol geeting load on site.
Regards,
Keyur Shah
mihir soni41 reputationPosted May 10, 2010, 10:24 PM EDT