Solved

webusercontrol parent page

Posted on 2009-04-06
4
213 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 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