簡體   English   中英

html Head標記處的runat =“ server”導致c#嵌入式代碼塊無法轉換為客戶端代碼

[英]runat=“server” at html Head tag causing c# embedded code blocks not convert to client side code

當我在head標簽和帶有<%= WebAppInstance %>值的一些css href中添加runat="server"時。 <%= WebAppInstance %>證明<%= WebAppInstance %>未轉換為客戶端代碼。 我希望下面的代碼可以澄清我的問題。

C#.Net代碼:

<head id="Head1" runat="server">
    <meta http-equiv="X-UA-Compatible" content="IE=9" />
    <title>Testing</title>
    <link rel="stylesheet" href="<%= WebAppInstance %>/bucket/css/bootstrap.min.css" />
</head>

HTML代碼如下圖所示:

帶有突出問題的HTML代碼您能告訴我發生了什么嗎? 謝謝!

請刪除<%=之后的空格字符。 這樣您的代碼將變為:

<%=WebAppInstance %>

其他使用完整版本:

<% Response.Write(WebAppInstance); %>

您也可以考慮以編程方式添加CSS

protected void Page_Init(object sender, EventArgs e)
{
    var link = new HtmlLink();
    link.Href = "~/bucket/css/bootstrap.min.css";
    link.Attributes.Add("rel", "stylesheet");
    link.Attributes.Add("type", "text/css");
    Page.Header.Controls.Add(link);
}

而且頭會像

<head runat="server">
    <meta http-equiv="X-UA-Compatible" content="IE=9" />
    <title>Testing</title>
</head>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM