ASP.. NET MasterPage,没有't显示我的<%=CodeBehindVar %>
本文关键字:显示 我的 CodeBehindVar MasterPage NET 没有 ASP | 更新日期: 2023-09-27 18:09:30
下面是我想做的一个例子:
内容端(Structure.master):
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Structure.master.cs" Inherits="Structure" %>
<!DOCTYPE HTML>
<html>
<head runat="server">
<title>Bienvenue sur</title>
<meta charset="utf-8" content="" />
<link runat="server" href="App_Themes/Global/Metro.css?v=22" rel="stylesheet" type="text/css" />
<link runat="server" href="App_Themes/Global/Site.css?v=<%=Version %>" rel="stylesheet" type="text/css" />
<link runat="server" href="App_Themes/Global/Structure.css?v=22" rel="stylesheet" type="text/css" />
和代码隐藏(Structure.master.cs):
using System;
using System.Linq;
using BaseInstanceEntity = Library.Common.Entities.BaseEntities.BaseInstanceEntity;
using BaseInstanceManager = Library.Manager.BaseInstanceManager;
public partial class Structure : System.Web.UI.MasterPage
{
public string Version { get; set;}
protected void Page_Load(object sender, EventArgs e)
{
Version = System.Configuration.ConfigurationManager.AppSettings["Version"].Replace(".", "");
如所示,我想将Version
变量显示在标题中,作为缓存控件。当我执行上面的代码时,行上的结果是:
<link href="../App_Themes/Global/Site.css?v=<%=Version %>" rel="stylesheet" type="text/css" />
就像代码没有被解释一样。我找不到解释。为什么会发生这种情况?
这个问题我来晚了但是当我需要动态创建CSS链接时我只需要在后面的代码中生成整个标签然后像这样把它放在标记上:
public partial class WebForm1 : System.Web.UI.Page
{
public string link;
protected void Page_Load(object sender, EventArgs e)
{
string ver = "1.0.0";
link = "<link rel='"stylesheet'" href='"../App_Themes/Global/Site.css?v=" + ver + "'"/>";
}
}
然后标记
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<%= link %>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
希望这将帮助其他人谁来到这个页面!
也许应该是这样的:
<link runat="server"
href='<%# string.Format("{0}?v={1}", Page.ResolveUrl("~/App_Themes/Global/Site.css"), Version)%>'
type="text/css" />
public static string Version
{
get
{
Assembly asm = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);
return String.Format("{0}.{1}", fvi.ProductMajorPart, fvi.ProductMinorPart);
}
}