![]() | CYQ.Data componentsCYQ.Data support multi-database application [Txt,Xml,Access, MSSQL, Oracle,SQLite,MySql], help easily and quickly to develop your project |
CYQ.Data.Xml MutilLanguage多语言类演示示例
Guide |
|
|
| #TopicOwner |
下面用CYQ.Data 数据框架 已封装好的多语言类来演示一个完整示例 1:新建网站项目:MutilLanguageDemo 2:接着项目添加引用 CYQ.Data 数据框架 V4.0版本 来实现对Xml的操作: 3:新建Lang.Xml,内容如下: <?xml version="1.0" encoding="utf-8" ?>
<root> <div id="title" eng="英文标题" cus="自定义标题">中文标题</div> <div id="autumn" eng="Autumn" cus="路过秋天">秋色园</div> <div id="url" eng="http://www.cyqdata.cn/english" cus="http://cyq1162.cnblogs.com">http://www.cyqdata.cn</div> </root> 最后项目截图如下:
这里演示用Cookie来设置语言版本,因此配置文件需要设置一下域名如下: <appSettings> <add key="Domain" value="localhost:9690"/> </appSettings> 演示用的就是localhost:9690,你懂的。
下面是Default.aspx的前后台代码: 前台的html: <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="btnChina" runat="server" Text="中文输出" OnClick="btnChina_Click" /> <asp:Button ID="btnEnglish" runat="server" Text="英文输出" OnClick="btnEnglish_Click" /> <asp:Button ID="btnCustom" runat="server" Text="自定义输出" OnClick="btnCustom_Click" /> <p>html:<%=lang.Get("autumn") %></p> <p>cs :<asp:Label ID="labUrl" runat="server" Text=""></asp:Label></p> </div> </form> </body> </html> 说明: 1:有三个按钮,通过点击来切换语言。 2:标题,一个被切换成不同语言的标签。 3:使用语法获取如:<%=lang.Get("autumn") %>: 4:服务端对控件赋值。 后台CS代码: protected MutilLanguage lang = null; //定义全局变量 protected void Page_Load(object sender, EventArgs e) { if (lang == null) { lang = new MutilLanguage(Server.MapPath("Lang.xml"), false); } if (!IsPostBack) { //设置页面标题和Lable this.Title = lang.Get("title"); labUrl.Text = lang.Get("url"); } } //三个按钮设置Cookie后然后刷新界面。 protected void btnChina_Click(object sender, EventArgs e) { lang.SetToCookie(LanguageKey.China); Response.Redirect(Request.RawUrl); } protected void btnEnglish_Click(object sender, EventArgs e) { lang.SetToCookie(LanguageKey.English); Response.Redirect(Request.RawUrl); } protected void btnCustom_Click(object sender, EventArgs e) { lang.SetToCookie(LanguageKey.Custom); Response.Redirect(Request.RawUrl); } 接下来看一下最后的实现效果: 点击“中文输出”: 点击“英文输出”: 点击“自定义输出”:
最后提供下示例代码下载:点击进入下载页面 ![]() |
Post Comment
Bulletin
Article Search
Categories
- Platform for dynamic (20)
- Feedback (9)
- Guide (33)
- Principles (19)
- Project-Case (8)
- Business & Buy (2)
- Technology exchange (45)
New Article
- CYQ.Data Components Getting Started Guide [Part 5]-[MProc Execute Stored Procedures or SQL]
- CYQ.Data Components Getting Started Guide [Part 4]-[MAction Insert Delete Update]
- CYQ.Data Components Getting Started Guide [Part 3]-[MAction Get And Set Value]
- CYQ.Data Components Getting Started Guide [Part 2]-[MAction Data Query- Fill And Select]
- CYQ.Data Components Getting Started Guide [Part 1]
New Comment
- When some one searches for his necessary thing, therefore he/she wishes to be available that in detail, so that thing is maintained over here.
- This is my first time pay a quick visit at here and i am in fact happy to read everthing at alone place.
- I truly appreciate this blog article.Really thank you! Cool.
- please pay a visit to the web sites we follow, like this one particular, as it represents our picks in the web
- Really enjoyed this post.Really thank you!
- Really enjoyed this article.Really looking forward to read more. Great.
- poker bonuses What are the norms of copyright of web content? How as it different from Patent?
- Wow! Thank you! I permanently needed to write on my blog something like that. Can I implement a fragment of your post to my site?
- This website was how do I say it? Relevant!! Finally I ave found something that helped me. Cheers!
- I was reading through some of your content on this internet site and I believe this web site is very informative ! Continue posting.