?
Solved

webusercontrol parent page

Posted on 2009-04-06
4
Medium Priority
?
217 Views
Last Modified: 2013-12-17
I have an aspx page. In it is a webusercontrol.
In ascx.cs I want to know the name of the aspx page that the webusercontrol is. How do I do that?
0
Comment
Question by:johnkainn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:amazingwolf1
ID: 24076178
use:

Response.Write(System.Web.HttpContext.Current.Request.Url.AbsolutePath);

this will give you the page path, you can parse this string to get the page name.
0
 
LVL 4

Accepted Solution

by:
amazingwolf1 earned 500 total points
ID: 24076194
Or, instead of parsing (still in your ascx code behind):

public string GetName()
{
string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePathSystem.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);     string sRet = oInfo.Name;     
return sRet; 
}

Open in new window

0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 24076222
you can also try:

String fileName = Page.AppRelativeVirtualPath.Substring(Page.AppRelativeVirtualPath.IndexOf("/") + 1);
0
 
LVL 53

Assisted Solution

by:Ryan Chong
Ryan Chong earned 500 total points
ID: 24076255
String fileName = Page.AppRelativeVirtualPath.Substring(Page.AppRelativeVirtualPath.LastIndexOf("/") + 1);

or this:

String fileName = Request.ServerVariables["SCRIPT_NAME"].Substring(Request.ServerVariables["SCRIPT_NAME"].LastIndexOf("/") + 1);
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question