检查页眉中的会话值

时间:2012-11-15 06:45:33

标签: asp.net css

如何检查标题中的会话值并选择样式表链接?

<head>
     // if session["culture"] equal EN choose  
     // <link href="/CSS/MenuEN.css" rel="stylesheet" type="text/css" />
     // else choose
     // <link href="/CSS/MenuFA.css" rel="stylesheet" type="text/css" />
</head>

5 个答案:

答案 0 :(得分:2)

试试这个:

<head>
    <asp:PlaceHolder ID="MyLink" runat="server">
        <link href="/CSS/Menu<%= Session["Culture"].ToString() %>.css" rel="stylesheet" type="text/css" />
    </asp:PlaceHolder>
</head>

答案 1 :(得分:1)

试试这个

protected void Page_Load(object sender, EventArgs e)
{
        HtmlLink link = new HtmlLink();
        link.Attributes.Add("rel", "stylesheet");
        link.Attributes.Add("type", "text/css");
        if (Session["culture"] == "EN")
            link.Href = "/CSS/MenuEN.css";
        else
            link.Href = "/CSS/MainFA.css";
        this.Header.Controls.Add(link);
}

或者这个

<head>
<%= (Session["culture"] == "EN") ? 
    "<link href='/CSS/MenuEN.css' rel='stylesheet' type='text/css' />" : 
    "<link href='/CSS/MainFA.css' rel='stylesheet' type='text/css' />"
%>
</head>

答案 2 :(得分:1)

我用那个

HtmlLink link = new HtmlLink();
    if (Session["Culture"].ToString() == "EN")
        link.Href = "/CSS/MenuEN.css";
    else if (Session["Culture"].ToString() == "FA")
        link.Href = "/CSS/MenuFA.css";
    link.Attributes.Add("rel", "stylesheet");
    link.Attributes.Add("type", "text/css");
    this.head.Controls.Add(link);

答案 3 :(得分:1)

我可能会做这样的事情......

<head>
<asp:PlaceHolder id="linkEN" runat="server">
<link href="/CSS/MenuEN.css" rel="stylesheet" type="text/css" />
</asp:PlaceHolder>
<asp:PlaceHolder id="linkFA" Visible="false" runat="server">
<link href="/CSS/MainFA.css" rel="stylesheet" type="text/css" />
</asp:PlaceHolder>
</head>

然后在你的代码中......

protected PlaceHolder linkEN;
protected PlaceHolder linkFA;

void Page_Load(object sender, EventArgs e)
{
        if (Session["culture"] != "EN")
        {
            linkEN.Visible = false;
            linkFA.Visible = true;
        }
}

答案 4 :(得分:1)

我使用此代码。

HtmlLink link = new HtmlLink();
    if (Session["Culture"].ToString() == "EN")
        link.Href = "/CSS/MenuEN.css";
    else if (Session["Culture"].ToString() == "FA")
        link.Href = "/CSS/MenuFA.css";
    link.Attributes.Add("rel", "stylesheet");
    link.Attributes.Add("type", "text/css");
    this.head.Controls.Add(link);