Without Refreshing Page, How to convert language Using Local Resources File

Posted by Pkanwar under ASP.NET on 3/6/2013 | Points: 10 | Views : 1258 | Status : [Member] | Replies : 5
Hi,

We have to change language in asp.net page, But Problem is that, When we change the language, Every Time page is Refreshed and data is lost. Here we are using Local Resources File.
In .cs file have following code, it is inherited from Base Class
protected void ddllanguage_SelectedIndexChanged(object sender, EventArgs e)
{
Session["myapplication.language"] = this.ddllanguage.SelectedValue.ToString();
Response.Redirect(Request.Url.ToString());
}
In Base.cs Class have:

protected override void InitializeCulture()
{
if (Session["myapplication.language"] != null)
{
string selectedLanguage = Session["myapplication.language"] as string;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage);
}
}

Thanks




Responses

Posted by: Oswaldlily on: 3/6/2013 [Member] Starter | Points: 25

Up
0
Down
Include this

protected void ddllanguage_SelectedIndexChanged(object sender, EventArgs e)
{
Session["myapplication.language"] = this.ddllanguage.SelectedValue.ToString();
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(Session("myapplication.language"))
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Session("myapplication.language"))
Response.Redirect(Request.Url.ToString());
}

Pkanwar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pkanwar on: 3/6/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks for Reply
But still, When change language, data in Input field is lost..

Pkanwar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 3/6/2013 [Member] Starter | Points: 25

Up
0
Down
May i know where is your dropdownlist?

In master page or content page?

Pkanwar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pkanwar on: 3/6/2013 [Member] Starter | Points: 25

Up
0
Down
In content Page have drop down list.

Pkanwar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 3/6/2013 [Member] Starter | Points: 25

Up
0
Down
In the page load of dropdownlist include this

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load


If(!Page.IsPostBack){
if(Session["myapplication.language"] !="") {
If Session("myapplication.language") = "zh-CN" {
ddl.SelectedIndex = 2
ddl.SelectedValue = Thread.CurrentThread.CurrentUICulture.Name
}
}
}


Pkanwar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response