September 2003
Intermediate to advanced
624 pages
14h 27m
English
You need to format dates and currency values according to the culture of the client rather than the server.
Use client culture and encoding to return data to the client formatted according to the client’s localization settings rather than the server’s settings.
The sample code-behind for the Web Forms page contains one event handler and a single method:
Form.LoadCreates the CultureInformation object based on the
user’s settings.
RefreshData( )This method sets the CurrentCulture for the
current thread and demonstrates the effect on output of different
data types.
The C# code for the code-behind is shown in Example 3-5.
Example 3-5. File: ADOCookbookCS0305.aspx.cs
// Namespaces, variables, and constants using System; using System.Threading; using System.Globalization; using System.Data; using System.Data.SqlClient; // This value would normally be retrieved from a user profile. private String DEFAULTUSERCULTURE = "en-US"; private CultureInfo ci; // . . . private void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) ci = new CultureInfo(DEFAULTUSERCULTURE); else { // Create the CultureInfo object as specified by the user. if(enUsRadioButton.Checked) ci = new CultureInfo("en-US"); else if(enCaRadioButton.Checked) ci = new CultureInfo("en-CA"); else if(jaJpRadioButton.Checked) ci = new CultureInfo("ja-JP"); else if(frFrRadioButton.Checked) ci = new CultureInfo("fr-FR"); } RefreshData( ); } private void ...Read now
Unlock full access