• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 413
  • Last Modified:

<title> tag rendering on three lines

Hello All

I have a master page title tag in my header

<title>My Title</title>

I have a pageload that sets it dynamically

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Dim strTitle As String = Me.Page.Header.Title.ToString()
      Page.Title = strTitle
End Sub

This works fine but it renders the HTML code like this:

<title>
      About Us
</title>

This messes up my Indexing as it sees the title as blank if it's not on one line.

My question is, "How do I render the <title></title> all on one line.

I have fiddled and can output the tag in one line but I must be rendering it too late because, ASP.NET is adding another <title> tag in over the three lines in addition to the one I output.

Any help would be most appreciated.

Cheers
Don Croswell
0
donaldcroswell
Asked:
donaldcroswell
  • 3
  • 2
1 Solution
 
VIkasumitCommented:
Hi,

I am not sure how it mess up your indexes, since you must be indexing using DOM structure and not as Text File. If you do so, than I prefer you to use DOM structure , very much like indexing XML file.

If you still want it that way , you can do this trick

declare a protected member in code behind
protected Title as string

page_load
Title= New title
end page_load

in aspx page just do <title><%=Me.title%></title> now you can render it the way you want

Not sure if this can be done without this trick, but this trick use less brain of mine than searching of correct solution, that must be like Trapping the Title Render call of HTMLWriterclass and than removing Line break character etc..

VIkasumit
0
 
sukumar_diyaCommented:
Hi,
Please try the following.. Hope it may help you..

1. Change the title tag as server control ie..
  <title id="pageTitle" runat="server"></title>

2. Create a property in the master page so that we can access the property
public string MasterPageTitle
{
set{pageTitle.Text = value;}
}

3. Set the value.. Suppose myMaster is instance for ur master object than
myMaster.MasterPageTitle = "Yeah!! It Works"

Please check and tell me ...

Suk

0
 
donaldcroswellAuthor Commented:
Hello Vika


The following code in the Master Page still produced the <title> tag over three lines

***********Start Code********************
<script language="VB" runat="server">
      protected MasterPageTitle As String
      Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            MasterPageTitle = Me.Page.Header.Title.ToString()
      End Sub
</script>
<head id="TCUHeader" runat="server">
      <title><%= MasterPageTitle %></title>

**********End Code**********************

If I pull the <title><%= MasterPageTitle %></title> out of the Master and put it in the aspx page I get the error
'MasterPageTitle' is not a member of 'mypage_aspx'.

Or if I hard code the aspx file with <title>Hello World</title> it will render it, but then also add in the <title> again over three lines. Obviously the title tag in my aspx page is not being seen yet when the Master is adding it's three line tag in.

Do you know what I am doing wrong?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
VIkasumitCommented:
Hi,

I read your message wrong i guess, or You understand my solution wrong ..:o)

YOu need to set the title of the page, that when it renders it render as <title>your title</title>

right...

if you want to achieve this than use my code without using
MasterPageTitle = Me.Page.Header.Title.ToString() ...It iwll pick the current title and set it on the MasterPageTitle...


even if you want to do that, than Trim vbcrlf from the MasterPageTitle and it will remove trailing info and render it correctly


VIkasumit
0
 
donaldcroswellAuthor Commented:
Thanks Vika

I got through it with a hack

<script language="VB" runat="server">
      Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                     lit1.Text = "<title>" & Me.Page.Title & "</title>"
                     title1.visible = False
      End Sub
</script>
<head id="TCUHeader" runat="server">
<asp:literal runat="server" id="lit1" />
<title runat="server" id="title1">This title renders on three lines</title>

Not the best solution but it works.

Thanks for your input.

Cheers
Don Croswell
0
 
VIkasumitCommented:
Hi,

Its always a pleasure to see a solution ..:o)

VIkasumit
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now