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);
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"
This code helps:
string filename = Path.GetFileName(Request.Url.AbsolutePath);
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.