Reading Page Title?

  • Thread starter Thread starter Chad A. Beckner
  • Start date Start date
C

Chad A. Beckner

Does anyone know how to read the page title the executing page, using
ASP.NET? I thought that this could be accessed using the Controls
collection, but I can't seem to figure it out.

Thanks!

Chad
 
unless you put runat=server on the title tag in the html, it will be inside
one the literals in the page controls collection.

-- bruce (sqlwork.com)
 
Ok, any idea of how to access this?

Chad

bruce barker said:
unless you put runat=server on the title tag in the html, it will be inside
one the literals in the page controls collection.

-- bruce (sqlwork.com)
 
Chad A. Beckner said:
Does anyone know how to read the page title the executing page, using
ASP.NET? I thought that this could be accessed using the Controls
collection, but I can't seem to figure it out.

You have to use:

<head>
<title runat="server" id="myTitle">Page title</title>
</head>

Then in your code you can access myTitle.InnerText to get the text.

If a given page doesn't have a <title> with runat="server", then there is no
way to retrieve the page title (if there is one).
 
But that won't work on static .htm files. I also need to access the meta
tags (since my site template .ascx file is generating the <head> element).
Ideas?

Chad
 
Chad A. Beckner said:
But that won't work on static .htm files. I also need to access the meta
tags (since my site template .ascx file is generating the <head> element).
Ideas?

You can't do it.
 
So, I can't parse the tags (or controls) of the page that is executing and
retrieve values?

Chad
 
Chad A. Beckner said:
So, I can't parse the tags (or controls) of the page that is executing and
retrieve values?

No. On the server side, you have access only to server-side controls. These
are the controls marked with runat="server".
 
Back
Top