Get title of page

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

Is there an easy way to get the title of the aspx page I am on?

Thanks,

Tom
 
Request.ServerVariables("PATH_INFO") and then strip off the path in front
if you don't want the path.
 
Chris Botha said:
Request.ServerVariables("PATH_INFO") and then strip off the path in front
if you don't want the path.

I assume this works everytime, unlike the HTTP_REFERER?

Thanks,

Tom
 
Well, give it a shot and see, it is the same as the old asp
Request.ServerVariables("PATH_INFO") before dotnet. It may give an invalid
name if you do a Server.Transfer call in the code-behind, other than that it
should work.
 
Add a ID=”whatever” and a Runat=”Server”
to the Title element on the aspx page.

<title runat="server" id="pageTitle"></title>

Then, in code-behind :

protected System.Web.UI.HtmlControls.HtmlGenericControl pageTitle;
pageTitle.InnerText = "Whatever you want to place here -” + anyvariable ;

If you want to get the aspx page's name, per your followup post, use :

string pagename = System.IO.Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"]);

That will return : "WhateverThePageNameIs.aspx".
You can insert that value in the "anyvariable" variable.




Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top