Solved

webusercontrol parent page

Posted on 2009-04-06
4
216 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 52

Expert Comment

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

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

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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

719 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