生成第二个标题标签的母版页
我在母版页中有一个简单的页面(好吧,在母版中的母版中)。
在顶级母版中,我有 head
标签和 runat="server"
,其中包含许多位,例如脚本、样式表等,还有一个 contentplaceholder。这里没有标题标签。
在使用该母版的页面中,占位符的内容包含 其中的
位。我真的必须把它放在那里。
不幸的是,当页面呈现时,我得到了我的标题,这一切都很好,但也得到了第二个空白标题标签 - 我推测是由 .NET 转储到那里的。
有什么办法可以阻止第二个标题标签的出现吗?
I have a simple page inside a master page (well, in a master in a master).
In the top master I have the head
tag with runat="server"
, with a number of bits such as scripts, stylesheets, etc. and also a contentplaceholder. There is no title tag here.
In the page that uses this master, the content for the placeholder contains the<title>pagename</title>
bit in it. I really have to set it in there.
Unfortunately when the page is rendered I get my title which is all good, but also get a second blank title tag - I presume dumped in there by .NET.
Is there any way of stopping this second title tag coming out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据记忆,通过将 runat="server" 放在</code>(如果还没有)。
上,.Net 会自动添加一个
我认为(尚未测试)是,如果在您的母版页中,您确实
在母版页的标题中明确设置了标题标签,并设置了对错误作品的可见性。我认为。
From memory, by virtue of putting the runat="server" on the
<head>
.Net automagically adds a<title>
if there isn't one already.I think (haven't tested it) is if in your masterpage you do
setting the Title tag explicitly in the Head of the masterpage and setting visibility to false works. I think.
您不必手动将</code> 插入到头部。<br><br /> 只需通过代码设置 <code>Page.Title = "title"</code> 或通过标记设置 <code><%@ Page Title="My Title" .. %></code> 即可。<br /> ASP.NET 将计算出其余部分,并给出正确的标题。
You don't have to manually insert
<title>
to the head.Just set
Page.Title = "title"
by code, or<%@ Page Title="My Title" .. %>
by markup.ASP.NET will figure out the rest, and put the right title.
我认为使用:
如果您想在页面级别设置标题
,或者,
如果您想在母版页级别设置动态标题。
是确保不生成空的第二个标题标签的更好方法。
I think using:
If you want to set title at page level
Or,
If you want to set dynamic title at Master Page level.
is better way to make sure that empty second title tag is not generated.