vb.net 如何在母版页内的用户控件中获取内容页面名称?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14251518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get content page name in user control inside the master page?
提问by user576510
I have a user control in master page and I need to get content page's name (for example Home.aspx) in user control. Unfortunately I am not getting how to do it. Please guide and help me.
我在母版页中有一个用户控件,我需要在用户控件中获取内容页面的名称(例如 Home.aspx)。不幸的是,我不知道该怎么做。请指导和帮助我。
回答by tam tam
In Page_Load() Event of MasterPage.
在 MasterPage 的 Page_Load() 事件中。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string strPage = Page.AppRelativeVirtualPath;
}
}
It will return the child page's virtual path.
它将返回子页面的虚拟路径。
Ex: ~/Default.aspx
例如:~/Default.aspx
回答by VinayC
Try using Page.AppRelativeVirtualPathproperty - you can extract the page file name from the virtual path.
尝试使用Page.AppRelativeVirtualPath属性 - 您可以从虚拟路径中提取页面文件名。
回答by Srinivas
You can use Page.Title property.Use it in the page load function
您可以使用 Page.Title 属性。在页面加载功能中使用它
string Title = Page.Title;
回答by Dan Hunex
Add a property (say CurrentPage) in the master or in the base page that returns the current page and refer this from the User Control using
在返回当前页面的主页面或基页面中添加一个属性(比如 CurrentPage),并使用
var page ='<%=CurrentPage%>'

