Friday, December 17, 2010

How to localize with master page dropdown

1) Add followoing code on index change event of Master page Dropdown

protected void DropDownListSelectLanguage_SelectedIndexChanged(object sender, EventArgs e)
{
Session["Culture"] = DropDownListSelectLanguage.SelectedValue;
Server.Transfer(Request.Path);

}
2) Create a base class and inherit the content pages with it or call fuction on contents page
InitializeCulture() envet.


protected override void InitializeCulture()
{


try
{

if ((Session["Culture"] != null))
{
LanguageCulture = Session[EMDMCConstants.SessionCulture ].ToString();
if (LanguageCulture != "0")
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(LanguageCulture);
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(LanguageCulture);
base.InitializeCulture();

}
}

}
catch (Exception ex)
{
string _customException = "###Class Name - BaseClass.cs Source Function Name -InitializeCulture, ParameterCount - 0###";
LogManager.SetException(ex, null, _customException);

throw ex;


}





}

3) Do not forgot to add resx files of same page for this you can take reff of any site.

No comments: