加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.NET内联编码:变量名不会被值替换

发布时间:2020-12-16 07:26:16 所属栏目:asp.Net 来源:网络整理
导读:我有一个ASP.NET页面.在页面加载中我设置了一个公共变量的值.在内联编码部分,我正在加载一个CSS,它是一个名称在公共变量中可用的文件夹.我的 HTML标记如下 %@ Page Language="C#" EnableEventValidation="false" AutoEventWireup="true" CodeFile="MyPage.as
我有一个ASP.NET页面.在页面加载中我设置了一个公共变量的值.在内联编码部分,我正在加载一个CSS,它是一个名称在公共变量中可用的文件夹.我的 HTML标记如下

<%@ Page Language="C#"  EnableEventValidation="false" AutoEventWireup="true" CodeFile="MyPage.aspx.cs"  Theme="GridView" Inherits="GUI.MyPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>MyPage</title>
<link href="../Vendors/<%=vendorName%>/css/style.css" rel="stylesheet" type="text/css" />

</head>
 <body>
<%=vendorName %> <!-- here value is printed correctly -->
 ...
 </body>

并在我的代码后面

public partial class MyPage: MyCommonClass
 {
    public string vendorName = "";
     protected void Page_Load(object sender,EventArgs e)
     {
        vendorName = "ACLL";
     }

 }

但是当我运行页面时,<%= VEndorId%>没有替换它中的值.但是在Body中,它正确打印.但是在头部它没有来.我检查了ViewSource并找到源HTML如下

<link href="../Vendors/&lt;%=vendorName%>/Lib/css/tradein.css" rel="stylesheet" type="text/css" />

解决方法

这两个选项是:

<link href="<%= string.Format("../Vendors/{0}/css/style.css",vendorName) %>" type="text/css" rel="Stylesheet" /> // as Greco stated

<style>
  @import url("../Vendors/<%=vendorName%>/css/style.css");
</style>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读