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)?