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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
mihir soniPosted May 11, 2010, 2:24 AM
Keyur ShahPosted May 11, 2010, 2:11 AM
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 soniPosted May 11, 2010, 1:42 AM
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 ShahPosted May 10, 2010, 1:35 AM
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 soniPosted May 10, 2010, 1:26 AM