Solved

webusercontrol parent page

Posted on 2009-04-06
4
205 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
Comment Utility
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
Comment Utility
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 49

Expert Comment

by:Ryan Chong
Comment Utility
you can also try:

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

Assisted Solution

by:Ryan Chong
Ryan Chong earned 125 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now