国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

asp.net2.0 國際化

2019-11-15 02:30:18
字體:
來源:轉載
供稿:網友

asp.net2.0 國際化

公司業務需要在國外開展了, 因此以前的系統要做多國語言了, 從網上搜集了好多資料, 最后選擇了一個比較簡單的方案

1. 打開vs2005, 新建網站,

  首先在配置文件中添加配置:

  <system.web>

    <globalization culture="auto" uiCulture="auto"/>

  </system.web>

  添加asp.net文件夾App_GlobalResources, 添加“資源文件”, 如下圖

  

2. 復制Resource.resx, 粘貼到App_GlobalResources文件夾下, 更改名稱為Resource.en-us.resx,內容更改如下:

  

3. asp:Label調用

  <asp:Label ID="Label1" runat="server" Text="<%$Resources:Resource,msg1%>"></asp:Label>

4. asp:Button調用

  <asp:Button ID="Button1" runat="server" Text="<%$ Resources:Resource,msg1 %>" OnClientClick="test();" />

5. js調用

  alert("<%=Resources.Resource.msg1 %>");

6 后臺調用

  <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>

  Label2.Text = Convert.ToString(GetGlobalResourceObject("Resource", "msg1"));

7. 圖片資源

  <asp:Image ID="Image1" runat="server" />

  然后在Page_Load中Image1.ImageUrl = "~/Image.aspx?culture=" + Convert.ToString(session["culture"]);

  

PRotected override void InitializeCulture()    {        base.InitializeCulture();        if (null != Session["culture"])        {            string c = Convert.ToString(Session["culture"]);            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(c);            Thread.CurrentThread.CurrentUICulture = new CultureInfo(c);                    }    }    protected void Page_Load(object sender, EventArgs e)    {        string c = Request["culture"];        System.Drawing.Bitmap img = (System.Drawing.Bitmap)GetGlobalResourceObject("Resource","test");        System.IO.MemoryStream ms = new System.IO.MemoryStream();        img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);        Response.ClearContent();        Response.ContentType = "image/jpeg";        Response.BinaryWrite(ms.ToArray());        img.Dispose();        ms.Dispose();        ms.Flush();    }

8 手動設置語言

  

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">            <asp:ListItem Value="zh-cn">中文</asp:ListItem>            <asp:ListItem Value="en-us">english</asp:ListItem>        </asp:DropDownList>
protected override void InitializeCulture()    {        base.InitializeCulture();        if (null != Session["culture"])        {            string c = Convert.ToString(Session["culture"]);            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(c);            Thread.CurrentThread.CurrentUICulture = new CultureInfo(c);        }    }       protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)    {        string c = DropDownList1.SelectedValue;        if (!string.IsNullOrEmpty(c))        {            Session["culture"] = c;            this.Response.Redirect("~/Default.aspx", true);        }    }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 陇南市| 大同县| 娄底市| 迭部县| 张北县| 南城县| 千阳县| 东安县| 建始县| 高雄市| 阿克陶县| 自贡市| 江华| 合江县| 洪雅县| 贵定县| 屯门区| 新乡市| 呼和浩特市| 青川县| 陕西省| 壶关县| 射洪县| 拉孜县| 铁岭县| 泗水县| 浪卡子县| 长治市| 千阳县| 钟山县| 姜堰市| 凯里市| 贵德县| 武隆县| 南木林县| 鄄城县| 修文县| 宝清县| 来安县| 怀柔区| 乌拉特后旗|