Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 设置多个html属性而不使用usercontrol或literal控件的最佳方法?_C#_Asp.net - Fatal编程技术网

C# 设置多个html属性而不使用usercontrol或literal控件的最佳方法?

C# 设置多个html属性而不使用usercontrol或literal控件的最佳方法?,c#,asp.net,C#,Asp.net,正在尝试找到向每个html元素动态添加方向属性的最佳方法。我知道如何获得方向 var dir = CultureInfo.CurrentCulture.TextInfo.IsRightToLeft ? "rtl" : "ltr"; 但是我需要找到一种优雅的方式来动态地将它添加到下面的html中 <!--[if lt IE 7]><html class="ie6" lang="en"><![endif]-->; <!--[if IE 7]><

正在尝试找到向每个html元素动态添加方向属性的最佳方法。我知道如何获得方向

var dir = CultureInfo.CurrentCulture.TextInfo.IsRightToLeft ? "rtl" : "ltr";
但是我需要找到一种优雅的方式来动态地将它添加到下面的html中

<!--[if lt IE 7]><html class="ie6" lang="en"><![endif]-->;
<!--[if IE 7]><html class="ie7" lang="en"><![endif]-->
<!--[if IE 8]><html class="ie8" lang="en"><![endif]-->
<!--[if gt IE 8]><!--><html lang="en"><!--<![endif]-->

将runat=server放入标记中:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" id="html_tag" runat="server">
您可以使用
控件输出整个结果。您可以在代码隐藏中生成整个摘录,然后将其提供给文本控件

或者,您可以创建一个公共函数:

public string Direction() {
    return (CultureInfo.CurrentCulture.TextInfo.IsRightToLeft) ? "rtl" : "ltr";
}
并在您的aspx页面中调用它:

<!--[if lt IE 7]><html class="ie6" lang="en" <%=Direction()%>><![endif]-->;
<!--[if IE 7]><html class="ie7" lang="en" <%=Direction()%>><![endif]-->
<!--[if IE 8]><html class="ie8" lang="en" <%=Direction()%>><![endif]-->
<!--[if gt IE 8]><!--><html lang="en" <%=Direction()%>><!--<![endif]-->

也可以使用设置,如果您要设置多个项目,这样做可能对您有利。让您的项目使用其他类,例如:

在页面上的其他位置(最好是上面),在页面上放置一个文本,并使其文本发出内联样式:

Literal.Text = String.Concat("<style> .useLTR {", CultureInfo.CurrentCulture.TextInfo.IsRightToLeft ? "direction: rtl;" : String.Empty, "} </style>");
Literal.Text=String.Concat(“.useLTR{”,CultureInfo.CurrentCulture.TextInfo.IsRightToLeft?”方向:rtl;“:String.Empty,”);

当您可以处理html标记中的属性时,为什么要使用文本?我完全忘记了我可以使用文本。FiveTools,在用户控件中保留打开的html标记会为我生成运行时错误(我在问题中描述了这一点)
<!--[if lt IE 7]><html class="ie6" lang="en" <%=Direction()%>><![endif]-->;
<!--[if IE 7]><html class="ie7" lang="en" <%=Direction()%>><![endif]-->
<!--[if IE 8]><html class="ie8" lang="en" <%=Direction()%>><![endif]-->
<!--[if gt IE 8]><!--><html lang="en" <%=Direction()%>><!--<![endif]-->
Literal.Text = String.Concat("<style> .useLTR {", CultureInfo.CurrentCulture.TextInfo.IsRightToLeft ? "direction: rtl;" : String.Empty, "} </style>");