我正在使用asp.net主题,并希望在用户更改其文化时更改同一主题中的工作表样式
有没有办法做到这一点?
知道我正在使用主题选择器控件,它将App_Theme文件夹中的所有主题作为数据源,并且不想为每种文化重复主题。
答案 0 :(得分:0)
如果您想要更改整个主题,可以覆盖StyleSheetTheme
中的Page
属性:
public override String StyleSheetTheme
{
get
{
string theme = "";
switch (CultureInfo.CurrentCulture.Name)
{
case "en-US":
theme = "YourTheme1"; break;
case "nl-NL":
theme = "YourTheme2"; break;
}
return theme;
}
}
此处提供更多信息:
How to: Apply ASP.NET Themes Programmatically
如果您只想更改CSS:
protected void Page_Init(object sender, EventArgs e)
{
string css = "";
switch (CultureInfo.CurrentCulture.Name)
{
case "en-US":
css = "YourCSS1"; break;
case "nl-NL":
css = "YourCSS2"; break;
}
HtmlLink cssLink = new HtmlLink();
cssLink.Href = string.Format("CSS/{0}.css", css);
cssLink.Attributes["rel"] = "stylesheet";
cssLink.Attributes["type"] = "text/css";
cssLink.Attributes["media"] = "all";
Page.Header.Controls.Add(css);
}