をクリックして言語を変更するには。これは答えと必要なすべてのコードです。私はビジュアルスタジオ2010のマスターページにこれを作っています。
ページの読み込みにispostbackを使うことができます。
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;
}
}
そして後に我々はこの問題を解決するのに役立ちますボタンクリックやクッキー
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);
}
と最後のGlobal.asaxファイルを追加することができます。
.netタグの代わりにhtmlタグを使用している場合は、テキストコントロールを追加するためにこれらを使用できます。
<a><asp:Literal ID="Literal1" runat="server" Text="<%$Resources: PB, Home %>" /></a>
どのようにデフォルト言語をクッキーに設定できますか?私はクッキーの使用を知らない! – Handelika
// cookieをdefaultLanguageに設定します HttpCookie hc = new HttpCookie( "dil"); hc.Expires = DateTime.Now.AddDays(30); hc.Value = "tr"; HttpContext.Current.Response.Cookies.Add(hc); –
残念ながら私のC#はサポートしていません。私はC#4番目のバージョン=( – Handelika