其他字符更改标签“称号”,在后面的代码
问题描述:
我需要根据其内容,改变页面标题,然后我执行以下操作:其他字符更改标签“称号”,在后面的代码
HTML(CSS):
<title id="titleOfPage" runat="server"></title>
背后
titleOfPage.Text = news.Title;
代码,但是当我运行网页,我看到以下内容:
<title>
My custom title completely
</title>
我的自定义标题在起始处有以下字符“0D”+“0A”+“09”或ASCII eguivalente“013”+“010”“009”(回车+新行+水平制表符) “0D”+“0A”结束。
我如何才能正确显示?我需要搜索引擎(Google,Bing,...)。
news.Title
是正确的,没有空格,它的值是“我的自定义标题完全”。
感谢
编辑
我试图titleOfPage.Text = "My custom title completely";
,我也得到相同的结果
编辑II
我试图创建在代码隐藏属性,但结果是相同的,但是如果我把属性放在一个标签“div”文本看起来不错。
代码隐藏:
...
public string TitleOfPage { get; private set; }
...
TitleOfPage = news.Title;
HTML:
<head>
<title><%= TitleOfPage %></title>
...
</head>
<body>
<div><%= TitleOfPage %></div>
...
</body>
结果:
<title>
My custom title completely
</title>
<div>My custom title completely</div>
EDIT III
首先对不起,以前没有把这个。在我的例子中,我没有完全包含标签head
,全头标签如下<header runat="server">
,我不知道为什么,但如果我删除runat="server"
,它工作正常。
随后出现的财产 “的innerText” 的称号:
HTML:
<title id="TitleOfPage" runat="server"></title>
代码隐藏:
TitleOfPage.InnerText = news.Title;
感谢。
答
你是说ASP.NET将这些字符添加到你的标题?这听起来不对。
顺便说一句,我会删除您的服务器端标题标签,并设置Page.Title
。
看看我的一些网页,我看到他们中的一些人在我的标题文字周围有换行符。如果发生这种情况,那么我没有看到问题。空白区域基本上被浏览器删除,这不会产生不利影响。这是否造成问题?
@Jonathan Wood。我得到了同样的结果 – 2011-04-27 17:39:26
'news.Title.Length'返回什么? – 2011-04-27 17:42:44
'news.Title.Length'返回25个字符 – 2011-04-27 17:47:02