ich es nach einer langen Suche klicken lösen. Das ist die Antwort und alle Codes, die Sie brauchen. Ich mache dies für die Masterseite in Visual Studio 2010.
Sie können in Seitenladung ispostback verwenden.
protected void Page_Load(object sender, EventArgs e)
{
//only does it on non-postback because otherwise the selected
//value will not reach event handler correctly
if (!Page.IsPostBack)
{
dil = Thread.CurrentThread.CurrentCulture.Name;
}
}
nach, dann können wir Taste klicken und Cookies
protected void Button2_Click(object sender, EventArgs e)
{
dil = "en-US";
//var ci = new CultureInfo(dil); //TO_DO Route culture
//Thread.CurrentThread.CurrentUICulture = ci;
//Thread.CurrentThread.CurrentCulture = ci;
//Session["culture"] = ci;
//Sets the cookie that is to be used by Global.asax
HttpCookie cookie = new HttpCookie("CultureInfo");
cookie.Value = dil;
Response.Cookies.Add(cookie);
//Set the culture and reload the page for immediate effect.
//Future effects are handled by Global.asax
Thread.CurrentThread.CurrentCulture =
new CultureInfo(dil);
Thread.CurrentThread.CurrentUICulture =
new CultureInfo(dil);
Server.Transfer(Request.Path);
}
und letzte Datei global.asax hilft die Lösung dieses Problems hinzufügen.
//*
Public void Application_BeginRequest(Object sender, EventArgs e)
{
// Code that runs on application startup
HttpCookie cookie = HttpContext.Current.Request.Cookies["CultureInfo"];
if (cookie != null && cookie.Value != null)
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new
System.Globalization.CultureInfo(cookie.Value);
System.Threading.Thread.CurrentThread.CurrentCulture = new
System.Globalization.CultureInfo(cookie.Value);
}
else
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new
System.Globalization.CultureInfo("tr-TR");
System.Threading.Thread.CurrentThread.CurrentCulture = new
System.Globalization.CultureInfo("tr-TR");
}
}
//*
Wenn Sie HTML-Tags anstelle von .net-Tags verwenden, können Sie diese zum Hinzufügen von Textsteuerung verwenden.
<a><asp:Literal ID="Literal1" runat="server" Text="<%$Resources: PB, Home %>" /></a>
Wie kann ich die Standardsprache in Cookie setzen. Ich weiß nicht, Cookie zu verwenden! – Handelika
// Cookie auf defaultLanguage setzen HttpCookie hc = new HttpCookie ("dil"); hc.Expires = DateTime.Now.AddDays (30); hc.Value = "tr"; HttpContext.Current.Response.Cookies.Add (hc); –
Leider wird meine C# nicht unterstützt. Ich benutze C# 4. version = ( – Handelika