Remove extra spaces in the header of an ASP.NET HTML page?

I have a problem.

I assign the page title value using VB.NET as page.title = "a" , but when I launch the page and look in the original page view, I find that it displays as <title> a </title>

The problem is that I want to remove all spaces between the title tags and show it as <title>a</title>

Thanks in advance!

+4
source share
1 answer

As far as I know, this is just a quirk (bug?) With ASP.NET rendering.

I stumbled upon this a while ago and found this fix here: Strange blank space in the title tag . If this bothers you, just paste this into your page code to fix it:

 Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter) Dim stringWriter As New System.IO.StringWriter() Dim htmlWriter As New HtmlTextWriter(stringWriter) MyBase.Render(htmlWriter) Dim html As String = stringWriter.ToString() Dim t1 As Integer = html.IndexOf("<title>") Dim t2 As Integer = html.IndexOf("</title>") + 8 Dim newTitleTag As String = html.Substring(t1, t2 - t1) html = html.Replace(newTitleTag, String.Format("<title>{0}</title>", Me.Title)) writer.Write(html) End Sub 
+2
source

Source: https://habr.com/ru/post/1347049/


All Articles