开发者

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.


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


You should try the Request.Url.LocalPath property

string fileNameFromLocalPath = Path.GetFileName(Request.Url.LocalPath);


This code helps:

string filename = Path.GetFileName(Request.Url.AbsolutePath);


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"


You can also use (VB.Net):

Dim pageName as String = Page.GetType().Name

which replaces the .extension with an underscore

So from Default.aspx you would be returned Default_aspx

You can also use:

Dim pageName as String = CType(HttpContext.Current.CurrentHandler, Page).GetType().Name

Which will produce the same results as described above.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜