how to get the page name?

  • Thread starter Thread starter ma
  • Start date Start date
M

ma

Hello,

I want to get the name of current page. How can I do this?



For example if I am running the code from a page called deafult.aspx, it
should return me default.aspx and if I am running from a page called
mypage.aspx, it should return mypage.aspx. page.tostring() doesn't return
this value. Any suggestion?



Regards
 
There are a number of ways to do this including using the ServerVariables
collection and using Request.AbsoluteUrl and "chopping off" everything after
the last "/". But a ver easy way is to do:

Page.GetType().Name

that will return "YourPageName_aspx". You could replace the
underscore with a dot and you are done.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
 
Even simpler than that :

VB.NET :
Dim pagename as string = System.IO.Path.GetFileName(Request.ServerVariables("SCRIPT_NAME"))

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



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
Back
Top