标签:multilingual asp-net html c
我正在尝试在asp.net上建立一个多语言的网站,并且我需要在c Sharp中以编程方式将html tag dir属性从rtl设置为ltr,反之亦然.
现在我有3种语言,英语,希伯来语和俄语,我需要在它们之间切换.
每当我从ltr更改为rtl语言以及从rtl更改为ltr语言时,我都需要更改网站的方向
这是我的母版页示例
请帮我
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!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 runat="server">
<title></title>
<link href="CSS/Site-RTL.css" rel="stylesheet" type="text/css" />
</head>
<body id="html" runat="server">
<form id="theForm" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder" runat="server">
</asp:ContentPlaceHolder>
</div>
<div style="margin-top: 20px;">
<asp:LinkButton ID="btnSetEnglish" runat="server" Text="English" CommandArgument="en-GB"
OnClick="RequestLanguageChange_Click"></asp:LinkButton>
<asp:LinkButton ID="btnSetHebrew" runat="server" Text="Hebrew" CommandArgument="he-IL"
OnClick="RequestLanguageChange_Click"></asp:LinkButton>
<asp:LinkButton ID="btnSetRussian" runat="server" Text="Russian" CommandArgument="ru-RU"
OnClick="RequestLanguageChange_Click"></asp:LinkButton>
</div>
<div>
<asp:SiteMapDataSource ID="smdsMaster" runat="server" OnDataBinding="Page_Load" />
<asp:Menu ID="MenuMaster" runat="server" CssClass="menu" DataSourceID="smdsMaster"
Orientation="Horizontal" StaticDisplayLevels="2" StaticSubMenuIndent="16px" MaximumDynamicDisplayLevels="1">
<DataBindings>
<asp:MenuItemBinding DataMember="SiteMapNode" NavigateUrlField="Url" />
</DataBindings>
</asp:Menu>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
这是母版页后面的代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Localization.Classes;
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RequestLanguageChange_Click(object sender, EventArgs e)
{
LinkButton senderLink = sender as LinkButton;
//store requested language as new culture in the session
if (senderLink.CommandArgument == "he-IL")
{
// some code
}
else
{
// some code
}
Session[Global.SESSION_KEY_CULTURE] = senderLink.CommandArgument;
//reload last requested page with new culture
Server.Transfer(Request.Path);
}
}
解决方法:
在后面的代码中:
this.html.Attributes.Add("dir", "ltr");
一种替代方法(如果这种方法不起作用)是将属性直接放在标签上,并使用属性来填充它:
<body dir="<%:Dir%>">
public string Dir { get; set; }
// Set Dir in the on click event
protected void RequestLanguageChange_Click(object sender, EventArgs e)
{
LinkButton senderLink = sender as LinkButton;
//store requested language as new culture in the session
if (senderLink.CommandArgument == "he-IL")
{
Dir = "rtl";
}
else
{
Dir = "ltr";
}
Session[Global.SESSION_KEY_CULTURE] = senderLink.CommandArgument;
//reload last requested page with new culture
Server.Transfer(Request.Path);
}
标签:multilingual,asp-net,html,c
来源: https://codeday.me/bug/20191101/1982930.html
本站声明:
1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。