分享
 
 
 

asp.net开发国际化的程序十个例子

王朝asp·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

Globalized Web Applications & ASP.NET

by Max Poliashenko and Chip Andrews

例子1

(a)

<INPUT type=text value= <%=GetString(unTranslatedString ) %>>

(b)

Response.Write("<SELECT>")

For Each row In myRecordset

Reponse.Write("<OPTION")

If myRecordset!ID.value = oldSelection Then

Response.Write(" SELECTED>")

Else

Response.Write(">")

End If

Response.Write(GetLocalizedString(myRecordset!MyField.value)&

"</OPTION>")

Next

Response.Write("</SELECT>")

例子2

(a)

public class GlobalizedLabel : System.Web.UI.WebControls.Label

{

protected override void Render(HtmlTextWriter output)

{

output.Write(Translator.GetLocalizedString(Text));

}

}

(b)

Translator.GetLocalizedString("The amount of ")) + price.ToString(

) +

Translator.GetLocalizedString(" will be charged to your account.&quo

t;));

(c)

(new StringBuilder()).AppendFormat("The amount of {0:C} will be

charged to your account.", price);

(d)

<%@ Page language="c#" %>

<%@ Register TagPrefix="glb" NameSpace="GlobalControls&quo

t;

Assembly="GlobalComponents&quo

t;%>

<HTML>

<BODY>

<glb:GlobalizedLabel id=lblGlobal runat=server>Test Label

</glb:GlobalizedLabel>

</BODY>

</HTML>

例子3

/// <summary>

/// Validation messages are translated

/// </summary>

public class GlobalizedRequiredFieldValidator : RequiredFieldValidator

{

protected override void Render(HtmlTextWriter output)

{

Text = Translator.GetLocalizedString(Text);

ErrorMessage = Translator.GetLocalizedString(ErrorMessage);

base.Render(output);

}

}

... etc.

public class GlobalizedValidationSummary : ValidationSummary

{

/// <summary>

/// This header will be translated

/// </summary>

public new string HeaderText

{

get{return base.HeaderText;}

set{base.HeaderText = Translator.GetLocalizedString(value);}

}

}

例子4

<%@ Page language="c#" %>

<%@ Register TagPrefix="glb" NameSpace="AspNetDemo.Compone

nts"

Assembly="Components"

;%>

<HTML>

<HEAD>

<meta content="Microsoft Visual Studio 7.0" name="GENE

RATOR">

<meta content="C#" name="CODE_LANGUAGE">

</HEAD>

<body bgColor="#e4e4e0">

<h3 align="center">User Information</h3>

<form id="Form2" method="post" runat="server&q

uot;>

<glb:GlobalizedValidationSummary id="vSummary" runat="

server"

headertext="The following validation errors occurred:" />

<hr>

<table cellSpacing="0" cellPadding="0" width=&quo

t;100%" border="0">

<tr>

<td width="30%">Name</td>

<td>

<asp:textbox id="txName" runat="server">

</asp:textbox>

<glb:GlobalizedRequiredFieldValidator id="rfValidator1&quo

t;

runat="server" display=&

quot;dynamic"

controltovalidate="txName" ErrorMessage="Name is re

quired."

Text="required

" />

</td>

</tr>

<tr>

<td>Password</td>

<td>

<asp:textbox id="txPassword" TextMode="Password&

quot;

runat="server"></asp:textbox>

<glb:GlobalizedRequiredFieldValidator id="rfValidator2&quo

t;

controltovalidate="txPassword" runat=&

quot;server"

ErrorMessage="Password is required."

Text="minimum 5 characters" display=&q

uot;dynamic" />

</td>

</tr>

<tr>

<td>Confirm password</td>

<td>

<asp:textbox id="txPasswordConf"

TextMode="Password" runat="

server" />

<glb:GlobalizedCompareValidator id="cmpValidator1"

runat="server" display="Dyn

amic"

controltovalidate="txPasswordConf"

ErrorMessage="Passwords don't match. Please, re-

enter."

ControlToCompare="txPassword" operator="Equal"

type="String" Text="doesn't match"

; />

</td>

</tr>

<tr>

<td>Email</td>

<td>

<asp:textbox id="txEmail" runat="server">

;</asp:textbox>

<glb:GlobalizedRequiredFieldValidator id="rfValidator3&quo

t;

runat="server" display="d

ynamic"

controltovalidate="txEmail" ErrorMessage="Email is

required."

Text="required" />

<glb:GlobalizedRegularExpressionValidator id="EmailRegVali

dator"

validationexpression="\w+@\w+\.\w+" runat="server&q

uot;

ErrorMessage="Email format is invalid.

" controltovalidate="txEmail" di

splay="static">

user@domain.ext</glb:GlobalizedRegularExpressionValidator>

</td>

</tr>

<tr>

<td>Age</td>

<td>

<asp:textbox id="txAge" runat="server">&

lt;/asp:textbox>

<glb:GlobalizedRangeValidator id="rngValidator1"

runat="server" controltovalidate

="txAge"

MinimumValue="1" MaximumValue="199" Type="

;Integer"

ErrorMessage="Age is invalid."

display="static" Text="0 < age < 200" /&

gt;

</td>

</tr>

<tr><td>&nbsp;</td></tr>

<tr>

<td align="middle" colSpan="2">

<glb:GlobalizedLinkButton id="btUpdate"

runat="server" Text="Update

" />

&nbsp;

<glb:GlobalizedLinkButton id="btCancel"

runat="server" Text="Cancel

">

Cancel</glb:GlobalizedLinkButton>

</td>

</tr>

</table>

</form>

</body>

</HTML>

例子5

/// <summary>

/// Button that pops client-side dialog to confirm the action. It exposes

/// ConfirmMessage property to set its dialog message with "Are you sur

e?"

/// being a default. It relies on GlobalizedButton class to translate

/// its Text and ToolTip properties.

/// </summary>

public class GlobalizedConfirmButton : Button

{

private string m_ConfirmMsg = "Are you sure?";

/// <summary>

/// Message will be translated and displayed in confirmation dialog box.

/// </summary>

public string ConfirmMessage

{

set{m_ConfirmMsg = value;}

}

/// <summary>

/// Renders HTML and client javascript for confirmation box

/// </summary>

/// <param name="output"></param>

protected override void Render(HtmlTextWriter output)

{

if (Page.Request.Browser.JavaScript == true)

{

output.WriteLine(@"<script id='clientConfirmation'

language='javascript'><!--

function RUSure()

{if (confirm('" + Translator.GetLocalizedString(m_ConfirmMsg)

+ @"')) return true;else return false;}

//--></script>");

Attributes.Add("onclick","return RUSure();");

}

Text = Translator.GetLocalizedString(Text);

base.Render(output);

}

}

例子6

decimal d = 1234.556M;

d.ToString("C",new System.Globalization.CultureInfo("nl-NL&qu

ot;));

例子7

<configuration>

<system.web>

<globalization

responseEncoding="utf-8"

requestEncoding="utf-8"

fileEncoding="utf-8"

culture="en-CA"

uiCulture="de-DE"

/>

</system.web>

</configuration>

例子8

<%@ Page language="c#" Culture="ru-RU" ResponseEncodi

ng="utf-8" %>

例子9

/// <summary>

/// Page sets its Culture according to the user profile

/// to affect all the formatting on this page

/// </summary>

public class LocalizedPage: Page

{

public LocalizedPage()

{

this.Culture = Utility.GetUserContextCulture();

}

}

例子10

System.Threading.Thread.CurrentThread.CurrentUICulture =

new System.Globalization.CultureInfo("de-DE");

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有