0
有沒有一種方法可以從InitializeCulture訪問頭標籤,因此我可以設置頭標籤lang屬性。我得到的對象引用不設置到對象InitializeCulture對象引用中的頭標籤而不是對象的實例
protected override void InitializeCulture()
{
if (Request[PostBackEventTarget] != null)
{
string controlID = Request[PostBackEventTarget];
// Request.Form[Request[PostBackEventTarget]].ToString();
string selectedValue = Request.Form[LanguageDropDownID].ToString();
if (controlID.Equals(Request.Params.Get("__EVENTTARGET")))
{
Thread.CurrentThread.CurrentCulture = new CultureInfo(selectedValue);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedValue);
Page.Header.Attributes.Add("lang", selectedValue); // error
}
}
else
{
string culture = (HttpContext.Current.Profile as ProfileCommon).Preferences.Culture;
Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
HtmlHead header = Page.Header as HtmlHead;
header.Attributes.Add("lang", culture); // error
}
base.InitializeCulture();
}
問題是訪問head標籤和屬性添加到它 和實例也爲什麼我的頭標記輸出不同的HTML標籤如
<html lang="<%= (HttpContext.Current.Profile as ProfileCommon).Preferences.Culture %>" xmlns="http://www.w3.org/1999/xhtml">
<head lang='<%= (HttpContext.Current.Profile as ProfileCommon).Preferences.Culture %>' runat="server">
存在
輸出
<html lang="fa-IR" xmlns="http://www.w3.org/1999/xhtml">
<head lang="<%= (HttpContext.Current.Profile as ProfileCommon).Preferences.Culture %>">
也許你的一小段源代碼會給一些東西詳細說明 – rene 2011-12-27 21:26:41