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.
In Page_Load() Event of MasterPage.
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
尝试使用Page.AppRelativeVirtualPath属性 - 您可以从虚拟路径中提取页面文件名。
您可以使用Page.Title属性。在页面加载功能中使用它
string Title = Page.Title;
在主页或基页中添加一个属性(比如CurrentPage),返回当前页面并使用用户控件引用它
var page ='<%=CurrentPage%>'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.