473,320 Members | 1,978 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,320 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 5988
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.