Solved

webusercontrol parent page

Posted on 2009-04-06
4
215 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 125 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 51

Expert Comment

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

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

Assisted Solution

by:Ryan Chong
Ryan Chong earned 125 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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