home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / aspplus / doc / cultureencoding.aspx < prev    next >
Encoding:
Text File  |  2000-06-07  |  5.4 KB  |  176 lines

  1.  
  2. <%@ Register TagPrefix="Acme" TagName="SourceRef" Src="/quickstart/util/SrcRef.aspx"%>
  3.  
  4. <!-- #include virtual="/quickstart/aspplus/include/header.inc" -->
  5.  
  6. <h4>Setting Culture and Encoding</h4>
  7.  
  8. <div class="indent" style="font-family:Verdana; font-size:8pt;">
  9. <b> <img align="middle" src="/quickstart/images/bullet.gif">  </b>
  10. <a class="toc2" target="content" href="#encodings">Encodings</a><br>
  11. <b> <img align="middle" src="/quickstart/images/bullet.gif">  </b>
  12. <a class="toc2" target="content" href="#cultureinfo">Using CultureInfo</a><br>
  13. <b> <img align="middle" src="/quickstart/images/bullet.gif">  </b>
  14. <a class="toc2" target="content" href="#encoding">Using RegionInfo</a><br>
  15. </div>
  16.  
  17. <p>
  18. <hr>
  19.  
  20. <!--BEGIN SECTION-->
  21. <a name="encodings">
  22. <span class="subhead">Encodings</span>
  23.  
  24. <p>
  25. Internally ASP+ handles all string data as Unicode. By using the <b>ResponseEncoding</b>
  26. attribute in the following sample , ASP+ is asked to send the page also with
  27. UTF-8 encoding. Note, that any arbritrary encoding could be chosen without
  28. affecting the .aspx file. ASP+ also sets the charset attribute on the
  29. Content-Type of the HTTP header according to the value of ResponseEncoding. 
  30. This enables browsers to determine the encoding without the need to require a
  31. meta tag or to guess the right encoding from the content.
  32. <p>
  33.  
  34. <Acme:SourceRef 
  35.   RunSample="/quickstart/aspplus/samples/localize/i18n_encodings.aspx" 
  36.   ViewSource="/quickstart/aspplus/samples/localize/i18n_encodings.src"
  37.   Icon="/quickstart/aspplus/images/encoding1.gif"
  38.   Caption="i18n_encodings.aspx"
  39.   runat="server" />
  40.  
  41. <p>
  42. <i>
  43. (Note, that if some characters show up
  44. as empty rectangles, you have to install the additional language
  45. support for Japanese and Hebrew: On Windows 2000 open the Regional Options on the 
  46. Control Panel and add the required language support.)
  47. </i>
  48. <p>
  49.  
  50. This sample demonstrates using different national character sets
  51. on the same page. The page contains English text (ASCII), German
  52. text (contains one umlaut character), Japanese text and Hebrew
  53. text (uses dir="rtl"). The source for the page itself is stored 
  54. with codepage-neutral UTF-8 encoding, as specified in config.web:
  55.  
  56. <div class="code"><xmp>
  57. <configuration>
  58. <globalization 
  59.    fileencoding="utf-8"
  60.    ...
  61. />
  62. </configuration>
  63. </xmp></div>
  64. <p>
  65.  
  66. On the page itself the ResponseEncoding is specified on the 
  67. Page directive: 
  68.  
  69. <div class="code"><pre>
  70. <%@Page ... ResponseEncoding="utf-8"%>
  71. </pre></div>
  72. <p>
  73.  
  74. Note, that the responseencoding in config.web is also specified as "utf-8",
  75. so that repeating it on the page is redundant. But if the .aspx file is
  76. moved to another server, which does not use utf-8, the file would still 
  77. specify the right encoding.
  78.  
  79.  
  80. <!--BEGIN SECTION-->
  81. <br>
  82. <a name="cultureinfo">
  83. <br>
  84. <span class="subhead">Using CultureInfo</span>
  85. <p>
  86.  
  87. Code on ASP+ pages can use the <b>CultureInfo</b> class to supply
  88. localized settings. In the following sample, the properties of 
  89. a culture are displayed, initially the culture of the server:
  90.  
  91. <div class="code"><xmp>
  92. culture = CultureInfo.CurrentCulture;
  93. </xmp></div>
  94.  
  95. If the name of a new culture is submitted, it will be used
  96. instead:
  97. <div class="code"><xmp>
  98. culture = new CultureInfo(NewCulture.Value);
  99. </xmp></div>
  100.  
  101. The submitted culture is set to be the new default value and
  102. some properties are displayed:
  103. <div class="code"><pre>
  104. <%
  105. Thread.CurrentThread.CurrentCulture = culture;
  106. %>
  107. ...
  108. Current Culture is <%= CultureInfo.CurrentCulture.Name %>
  109. (<%=Thread.CurrentThread.CurrentCulture.Name%>),
  110. <%= CultureInfo.CurrentCulture.EnglishName %>/<%=CultureInfo.CurrentCulture.NativeName%>,
  111. The localized date is: <%= DateTime.Now.Format("D", CultureInfo.CurrentCulture) %>
  112. </pre></div>
  113.  
  114. <p>
  115. <Acme:SourceRef 
  116.   RunSample="/quickstart/aspplus/samples/localize/i18n_cultureinfo.aspx" 
  117.   ViewSource="/quickstart/aspplus/samples/localize/i18n_cultureinfo.src"
  118.   Icon="/quickstart/aspplus/images/encoding2.gif"
  119.   Caption="i18n_cultureinfo.aspx"
  120.   runat="server" />
  121.  
  122.  
  123.  
  124. <!--BEGIN SECTION-->
  125. <br>
  126. <a name="region">
  127. <br>
  128. <span class="subhead">Using RegionInfo</span>
  129. <p>
  130.  
  131. Code on ASP+ pages can use the <b>RegionInfo</b> class to also supply
  132. regional settings. In the following sample the properties of 
  133. a region are displayed, initially the default region of the server:
  134.  
  135. <div class="code"><pre>
  136. region = RegionInfo.CurrentRegion;
  137. ...
  138. Current region is <%= region.EnglishName %> (<%=region.NativeName%>), 
  139. currency is <%= region.CurrencySymbol %>.
  140. </pre></div>
  141.  
  142. On subsequent requests the entered region is displayed:
  143. <div class="code"><xmp>
  144. region = new RegionInfo(NewRegion.Value);
  145. </xmp></div>
  146.  
  147.  
  148.  
  149. <Acme:SourceRef 
  150.   RunSample="/quickstart/aspplus/samples/localize/i18n_regional.aspx" 
  151.   ViewSource="/quickstart/aspplus/samples/localize/i18n_regional.src"
  152.   Icon="/quickstart/aspplus/images/encoding3.gif"
  153.   Caption="I18N_Regional.aspx"
  154.   runat="server" />
  155.  
  156.  
  157.  
  158.  
  159. <h4>Section Summary</h4>
  160. <ol>
  161. <li>ASP+ can use pages, which are stored with utf-8 encoding, to support different national characters.
  162. <li>The CultureInfo class can be set and used programmatically to localize pages.
  163. <li>The RegionInfo class can be used to provide regional settings on ASP+ pages.
  164. </ol>
  165.  
  166. <!-- #include virtual="/quickstart/aspplus/include/footer.inc" -->
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.