how to get the page name?

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
 
G

Guest

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
 
J

Juan T. Llibre

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"]);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top