?
Solved

Showing Page Title Via ASP

Posted on 2011-10-21
13
Medium Priority
?
259 Views
Last Modified: 2012-05-12
Using classic ASP, how can I display the page title from the HTML code
<title>Example Page</title>

Open in new window

It is probably something pretty simple, but searching leads me to databases, etc.  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Example Page</title>
</head>

<body>
<p>The Name of this page is: </p>
</body>

</html>

Open in new window

And on the parse code, it would show:
The Name of this page is: Example Page
0
Comment
Question by:coreybryant
  • 3
  • 3
  • 2
  • +3
13 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 37009363
I presume your question is actually how to fetch the data from database, or get it into there?

<%
  ' here goes the code to query the database, whatever ...
  v_page_title = "Example Page"
  ' and you use that later on in the actual html
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title><%=v_page_title%></title>
</head>

<body>
<p>The Name of this page is: </p>
</body>

</html>

Open in new window

0
 
LVL 8

Expert Comment

by:Amit Khilnaney
ID: 37009471
In the coding view


The name of the page is  = Page.Title
The name of the page is = Page.Header.Title

Try with that

0
 
LVL 6

Expert Comment

by:matija_
ID: 37009504
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Example Page</title>
</head>

<body>
<p>The Name of this page is: <script language="JavaScript">document.write (document.title)</script></p>
</body>

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 29

Author Comment

by:coreybryant
ID: 37009533
No, no database is involved.

I tried
Page.Title

Open in new window

and
Page.Header.Title

Open in new window

but that just displayed
Page.Title
and
Page.Header.Title
respectively.

The JavaScript code did work, but I was hoping to use ASP if it is available.

Thank you!
0
 
LVL 8

Expert Comment

by:Amit Khilnaney
ID: 37009549
Apologies, that was for asp.net
0
 
LVL 31

Expert Comment

by:Wayne Barron
ID: 37009783
What exactly are you trying to show?
What is the title of the page, and where is the title coming from?
If not from a database, then where?
0
 
LVL 5

Expert Comment

by:Seonyx
ID: 37010751
I think what you need to do is store the page title as a variable like this:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%
Dim pagetitle
pagetitle = "Example Page"
%>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title><%response.write(pagetitle)%></title>
</head>

<body>
<p>The Name of this page is: <%response.write(pagetitle)%></p>
</body>

</html>
0
 
LVL 29

Author Comment

by:coreybryant
ID: 37011020
The page title is coming from the <title>
<title>Example Page</title>

Open in new window

I was hoping there was an easy way - almost similar to Seonyx way, but without having to add / store that in a separate field.

Corey
0
 
LVL 5

Expert Comment

by:Seonyx
ID: 37011434
I think you'll find this is the easiest way to do it.

There are two other ways I can think of to do what you want.

1) Don't use ASP - do it in javascript or jquery when the page is loaded in the client's browser. That is a bit more fiddly and won't work in all situations (i.e. if javascript is disabled).

2) Write some code on the server that reads the contents page in and searches for the title and parses its contents. This would be slower to execute and and require much more development/testing time.
0
 
LVL 31

Accepted Solution

by:
Wayne Barron earned 1200 total points
ID: 37011607
@Seonyx
Once you create the Variable, you do not have to use the response.write to write the variable's data out.

<%
Dim pagetitle
pagetitle = "Example Page"
%>

<%=pagetitle%>   <-- This is all that is needed, clean and neat.

Carrzkiss
0
 
LVL 29

Author Comment

by:coreybryant
ID: 37012010
Can that
<%
Dim pagetitle
pagetitle = "Example Page"
%>

Open in new window

be anywhere or does it need to be in the <head>?

Thanks!
0
 
LVL 5

Assisted Solution

by:Seonyx
Seonyx earned 600 total points
ID: 37013682
@carrzkiss yes you're absolutely right, though I used the full form for the sake of clarity.

@coreybryant  you can place that anywhere you like, even before the <html> tag and it will work just the same.
0
 
LVL 6

Assisted Solution

by:matija_
matija_ earned 200 total points
ID: 37013747
I think it's obvious by now, that it is IMPOSSIBLE to get the <title> with ASP without putting it in variable first. There is NO WAY to get it simply by reading/requesting <title> field because that command does not exist in classic ASP.

Experts here gave you solutions and you should either choose one of those, or give up.

Solution 1 (ASP variables):
<%
Dim strTitle
strTitle = "Example Page
%>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title><%=strTitle%></title>
</head>

<body>
<p>The Name of this page is: <%=strTitle%></p>
</body>

Open in new window


Solution 2 (JavaScript):

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Example Page</title>
</head>

<body>
<p>The Name of this page is: <script language="JavaScript">document.write (document.title)</script></p>
</body>

Open in new window

0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question