ASP.NET masterpages: how to insert markup in the head section inside the aspx?(ASP.NET 母版页:如何在 aspx 内的 head 部分插入标记?)
问题描述
我知道我可以 以编程方式访问使用母版页的页面的头部这种方式(在后面的代码中):
I know I can access the head section of a page which uses a masterpage programmatically this way (in code behind):
这只是一个例子(我想插入脚本和样式等):
This is only an example (I'd like to insert scripts and styles etc.):
this.Header.Title = "SSBqdXN0IHNldCB0aGUgcGFnZQ=="s title";
有没有一种简单的方法可以在 aspx 文件本身上以声明性方式执行此操作?
Is there a simple way to do this in a declarative way on in the aspx file itself?
有时插入客户端脚本或样式声明或指向外部资源的链接会很方便.
Sometimes it would be handy to insert a client script or a style declaration or a link to an external resource.
推荐答案
您可以通过在 head
中使用内容区域来做到这一点,与在 body 中使用的方式完全相同
页面.例如,在您的母版页中:
You can do this by using content regions in the head
, in exactly the same way as you would in the body
of the page. eg, In your masterpage:
<head>
<link type="text/css" rel="stylesheet" href="/styles/common1.css" />
<script type="text/javascript" src="L3NjcmlwdHMvY29tbW9uMS5qcw=="></script>
<asp:contentplaceholder id="ExtraStylesAndScripts" runat="server" />
</head>
然后在页面本身就像这样:
And then in the page itself just something like:
<asp:content contentplaceholderid="ExtraStylesAndScripts" runat="server">
<link type="text/css" rel="stylesheet" href="/styles/extra1.css" />
<link type="text/css" rel="stylesheet" href="/styles/extra2.css" />
<script type="text/javascript" src="L3NjcmlwdHMvZXh0cmExLmpz"></script>
<script type="text/javascript" src="L3NjcmlwdHMvZXh0cmEyLmpz"></script>
</asp:content>
这篇关于ASP.NET 母版页:如何在 aspx 内的 head 部分插入标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ASP.NET 母版页:如何在 aspx 内的 head 部分插入标记?


- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 使用 rss + c# 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01