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/<%=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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 如何为Bootstrap按钮创建Button_Click()事件?
- asp.net – 剑道:网格中的ComboBox – 将选定组合框的其他
- asp.net-mvc – 如何将查询字符串映射到MVC中的操作方法参数
- asp.net-mvc – 模拟FormsAuthentication.Authenticate()方
- asp.net – 用于Webapp和桌面/移动应用程序的OpenID OAuth身
- asp.net-mvc – 调试流畅的验证规则
- 从.NET开始 – ASP.NET,WPF,Silverlight或命令行C#?
- asp.net HC架构
- 集成EntLib实现ASP.NET MVC的异常处理
- asp.net-core – 对Post请求的两次调用:使用http 204和200
推荐文章
站长推荐
- .net – DataAnnotations与IDataErrorInfo
- asp.net – 超过了JavaScriptSerializer.MaxJson
- ASP.NET MVC SiteMap和/或安全修整
- 为什么我的客户端去服务器来检查在使用ASP.NET M
- asp.net – 使用区域时,“路由表中没有路由匹配提
- asp.net-core – ASP.NET Core – Swashbuckle没
- asp.net-core – 在Visual Studio 2017 RTM上,Br
- asp.net – ModelState.IsValid返回true,即使必需
- asp.net-mvc – 如何在编辑器模板中获取序列/数组
- asp.net-mvc – Html.BeginForm()工作正常,Html.
热点阅读