tailieunhanh - Localizing Client-Side Data in a Web Forms Application

[ Team LiB ] Recipe Localizing Client-Side Data in a Web Forms Application Problem You need to format dates and currency values according to the culture of the client rather than the server. | Team LiB Recipe Localizing Client-Side Data in a Web Forms Application Problem You need to format dates and currency values according to the culture of the client rather than the server. Solution 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 Creates 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 Namespaces variables and constants using System using using using using This value would normally be retrieved from a user profile. private String DEFAULTUSERCULTURE en-US private Cultureinfo ci . . . private void Page_Load object sender e if IsPostBack ci new Culturelnfo DEFAULTUSERCULTURE else Create the Cultureinfo object as specified by the user. if enU sRadioButton. Checked ci new Cultureinfo en-US else if ci new Cultureinfo en-CA else if ci new Cultureinfo ja-JP else if ci new Cultureinfo fr-FR RefreshData private void RefreshData if ci null Set the culture for the current thread. ci Retrieve details about the culture. Cultureinfo. Cultureinfo. Sample data that might come from a database displayed according to culture set by user. D d Double

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.