您的位置:首页 > 编程语言 > ASP

ASP.NET 网页的 title 有换行、空白字符的解决

2013-05-11 08:56 489 查看
在 ASP.NET 中,不论是通过 Page.Title 动态设置的,还是通过如下方式静态设置的:

<head runat="server">
<title>博石网络</title>
</head>


生成的源代码都是这个样子:

<head><title>
博石网络
</title></head>


可是我们需要的是这样的:

<head>
<title>博石网络</title>
</head>


微软也不知道怎么搞的,非要把 title 生成那种格式。

原因

head 设置了 runat="server"

解决办法

只有取消 head 的 runat="server" 了。

但是

Page.Title 不能用了;

通过 HtmlHead 添加 charset、keywrods、description 不能用了;

继续解决

标签这样写 <title id="_title" runat="server"></title>,通过 _title.InnerText 动态设置,生成的标签类似 <title id="_title">博石网络</title>,但是客户还是不喜欢,不喜欢有个 id="_title"。

再继续解决:

<head>
<title><asp:Literal ID="_title" runat="server"></asp:Literal></title>
</head>


然后设置 _title 的 Text 属性,也可以:

<head>
<asp:Literal ID="_titleBox" runat="server"></asp:Literal>
</head>


然后设置:_titleBox.Text = "<title>博石网络</title>";。两种方法都可以。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐