|
using System;
using System.Globalization;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TestWeb
{
public partial class _Default : Page
{
/// <summary>
/// Handles the Load event of the Page control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// Sets the <see cref="P:System.Web.UI.Page.Culture"/> and <see cref="P:System.Web.UI.Page.UICulture"/> for the current thread of the page.
/// </summary>
protected override void InitializeCulture()
{
// Retrieve culture information from session
string culture = Convert.ToString(Session["Culture"]);
// Check whether a culture is stored in the session
if (!string.IsNullOrEmpty(culture))
{
Culture = culture;
// Set culture to current thread
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
}
// Call base class
base.InitializeCulture();
}
/// <summary>
/// Handles the Click event of the RequestLanguageChange control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected void RequestLanguageChange_Click(object sender, EventArgs e)
{
LinkButton senderLink = sender as LinkButton;
if (senderLink != null)
{
// Store requested language as new culture in the session
Session["Culture"] = senderLink.CommandArgument;
// Reload last requested page with new culture
Server.Transfer(Request.Path);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.