問題
以變數動態變更圖檔目錄以實現多國語系方法
解決方法
架構如下:
以session紀錄"語系"變數,並在postback時觸發變更路徑的function以實現此目的
.aspx程式碼:
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head > </head> <body> <form id="form1" runat="server"> <asp:LinkButton ID="btnzh" runat="server" OnClick="btnzh_Click">繁中</asp:LinkButton>/<asp:LinkButton ID="btncn" runat="server" OnClick="btncn_Click">簡中</asp:LinkButton>/<asp:LinkButton ID="btnen" runat="server" OnClick="btnen_Click">English</asp:LinkButton> <br /> <br /> <img src="./<%=myver%>/cccq1.jpg" /><br /> </form> </body> </html>.cs程式碼:
namespace WebApplication1 { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Session["ver"] = "zh"; GetPath(); } /// <summary> /// 取得圖檔路徑 /// </summary> public void GetPath() { string _path = "img_"; myver= _path + Convert.ToString(Session["ver"]); } public string myver = ""; protected void btnzh_Click(object sender, EventArgs e) { Session["ver"] = "zh"; GetPath(); } protected void btncn_Click(object sender, EventArgs e) { Session["ver"] = "cn"; GetPath(); } protected void btnen_Click(object sender, EventArgs e) { Session["ver"] = "en"; GetPath(); } } }
沒有留言:
張貼留言