ASP.NET masterpages:如何在ASPX里面的头部插入标记? [英] ASP.NET masterpages: how to insert markup in the head section inside the aspx?
本文介绍了ASP.NET masterpages:如何在ASPX里面的头部插入标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以访问它采用了母版编程这种方式(在code后面)页面的头部分:
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 = "I just set the page's title";
有一个简单的方式来做到这一点的声明办法在在ASPX文件本身?
有时候会很方便插入客户端脚本或样式声明或外部资源的链接。
Sometimes it would be handy to insert a client script or a style declaration or a link to an external resource.
推荐答案
您可以在头使用内容的区域做到这一点
,以完全相同的方式,你会一样在页面的体
。例如,在你的母版:
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="/scripts/common1.js"></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="/scripts/extra1.js"></script>
<script type="text/javascript" src="/scripts/extra2.js"></script>
</asp:content>
这篇关于ASP.NET masterpages:如何在ASPX里面的头部插入标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文