473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How to get the page name of itself

ad
When I a webpage, say "MyPage.aspx", How to get the page name of itsef
(MyPage.aspx)?
Nov 19 '05 #1
6 5996
You can find the name through the ServerVariables Collection. Use the C#
example below to get the current page name.

Request.ServerVariables["SCRIPT_NAME"].ToString()

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
When I a webpage, say "MyPage.aspx", How to get the page name of itsef
(MyPage.aspx)?

Nov 19 '05 #2
A little bit more than that is needed.

That will return the page name *if* it's in the root.

If the page is in an application directory,
it will return a path which includes the virtual directory

You need to split the URL array to get just the page name.

Here's a routine which will return the script's name
no matter whether the page is in an application,
in the root, or in a deeply nested subdirectory.

script_name.aspx
------------------
<%@ Page Language="VB" %>
<html>
<head>
<title>Page Name</title>
</head>
<script runat="server">
Public Sub Page_Load(Sender As Object, E As EventArgs)
Dim strURL, arrayURL, pagename
strURL = Request.ServerVariables("SCRIPT_NAME")
arrayURL = Split(strURL, "/", -1, 1)
pagename = arrayURL(ubound(arrayURL))
script.text = pagename
End Sub
</script>
<html>
<body>
<form id="Form1" runat="server">
<p>
<asp:Label id="script" runat="server" /><BR>
</form>
</body>
</html>
------------


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Mark Fitzpatrick" <ma******@fitzme.com> wrote in message
news:uH**************@TK2MSFTNGP14.phx.gbl...
You can find the name through the ServerVariables Collection. Use the C# example below
to get the current page name.

Request.ServerVariables["SCRIPT_NAME"].ToString()

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
When I a webpage, say "MyPage.aspx", How to get the page name of itsef
(MyPage.aspx)?


Nov 19 '05 #3
ad
Thank!
But the "Request.ServerVariables["SCRIPT_NAME"].ToString()" will get the
whole path like:
/AppPath/SubPath/MyPage.aspx. But I only want the page name.
How can I do that?

"Mark Fitzpatrick" <ma******@fitzme.com> ¼¶¼g©ó¶l¥ó·s»D
:uH**************@TK2MSFTNGP14.phx.gbl...
You can find the name through the ServerVariables Collection. Use the C#
example below to get the current page name.

Request.ServerVariables["SCRIPT_NAME"].ToString()

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
When I a webpage, say "MyPage.aspx", How to get the page name of itsef
(MyPage.aspx)?


Nov 19 '05 #4
See my previous reply.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"ad" <ad@wfes.tcc.edu.tw> wrote in message news:u$**************@TK2MSFTNGP09.phx.gbl...
Thank!
But the "Request.ServerVariables["SCRIPT_NAME"].ToString()" will get the
whole path like:
/AppPath/SubPath/MyPage.aspx. But I only want the page name.
How can I do that?

"Mark Fitzpatrick" <ma******@fitzme.com> ¼¶¼g©ó¶l¥ó·s»D
:uH**************@TK2MSFTNGP14.phx.gbl...
You can find the name through the ServerVariables Collection. Use the C#
example below to get the current page name.

Request.ServerVariables["SCRIPT_NAME"].ToString()

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> When I a webpage, say "MyPage.aspx", How to get the page name of itsef
> (MyPage.aspx)?
>
>



Nov 19 '05 #5
You can get it by only one row of code by using System.IO.Path:
C#
string pagename =
System.IO.Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"])

"ad" wrote:
When I a webpage, say "MyPage.aspx", How to get the page name of itsef
(MyPage.aspx)?

Nov 19 '05 #6
Great shortcut, Jouni!
Thanks for posting it.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Jouni Karppinen" <Jo************@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
You can get it by only one row of code by using System.IO.Path:
C#
string pagename =
System.IO.Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"])

"ad" wrote:
When I a webpage, say "MyPage.aspx", How to get the page name of itsef
(MyPage.aspx)?

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil Powell | last post by:
URL: http://valsignalandet.com/cookiegrab.php?name=valIdentifier This page produces a cookie value and sends it back as HTML using PHP and Javascript to obtain it. This URL will be used as the...
7
by: Aaron Prohaska | last post by:
I have just run into a problem where I have a page that posts back to itself to execute code, except when the page does the post back it somehow executes code that is in our home page for the site....
4
by: dmiller23462 | last post by:
I'm trying to create a submission page for users to request PC/LAN Access....If they select "Yes" in the field asking about if they need Non Standard Software, I want several other HTML fields to...
12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
3
by: Andy Kasotia | last post by:
On the client once the user clicks the Submit button....in my code the following javascript function kicks off... onclick="return SubmitForm('frmCurrBuildings', 'CurrBuildings.asp', c_iLOADNEW,...
8
by: Galina | last post by:
Hello I have 6 dependent list boxes on my ASP page:  Faculty;  Lecturer;  Course;  Course occurrence;  Group;  Week commencing date. When faculty is selected, lists of lecturers and...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
17
by: =?Utf-8?B?Y2F0aGFyaW51cyB2YW4gZGVyIHdlcmY=?= | last post by:
Hello, I have build a website with approximately 30 html-pages. When I search this website in Google, I see the index.html or home.html on this website, but also other html-pages on this...
7
by: Andy B | last post by:
I have a class I am creating for data access. I need to access controls from inside the class that are on a particular page. How do I do this? or is creating an instance of the page class and using...
4
by: Mo | last post by:
I am trying to calculate credibility for new customers so they can attain open-account. I have set up a form (on test.php, and processed by the same page) into which feedback from their trade...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.