Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET - Current name of page from web user control?

I need to find out name of location where web user control is. Somethnig like HttpContext.Current.Request.Url.ToString(), but I get only page for this web user control.

like image 283
gormit Avatar asked May 25 '11 09:05

gormit


4 Answers

Request.Url.Segments will give you a string array. The last item is the page

like image 111
Sergio Avatar answered Oct 23 '22 04:10

Sergio


You should try the Request.Url.LocalPath property

string fileNameFromLocalPath = Path.GetFileName(Request.Url.LocalPath);
like image 34
VMAtm Avatar answered Oct 23 '22 06:10

VMAtm


This code helps:

string filename = Path.GetFileName(Request.Url.AbsolutePath);
like image 30
Billy Avatar answered Oct 23 '22 04:10

Billy


If you ask for Page.getType.name, you will get the name of the master, the aspx page. if you want the name of the ascx control you are working on, use me.GetType.Name.ToString if your control is in a directory MyDir and the name of your ascx is test.ascx then the result will be

"ASP.MyDir_test_ascx"

like image 45
frans eilering Avatar answered Oct 23 '22 05:10

frans eilering