[ACCEPTED]-How to determine which Child Page is being displayed from Master Page?-master-pages
I use this:
string pageName = this.ContentPlaceHolder1.Page.GetType().FullName;
It retuns the class name in this 3 format "ASP.default_aspx", but I find that 2 easy to parse for most purposes.
Hope that 1 helps!
It's better to let the ContentPage
notify the MasterPage
. That's 8 why the ContentPage
has a Master
Property and MasterPage
does not have 7 Child
property.
Best pratice in this is to define 6 a property or method on the MasterPage
and use this 5 through the Master
property of the ContentPage
.
If you use 4 this technique it's best to explicitly specify 3 the classname for the MasterPage. This 2 makes to use the MasterPage in the ContentPage.
Example:
//Page_Load
MyMaster m = (MyMaster)this.Master;
m.TellMasterWhoIAm(this);
Hope 1 this helps.
This sounds like a bad idea to start with. The 3 idea of the master is that it shouldn't 2 care what page is there as this is all common 1 code for each page.
I have had a reason to check the child page 9 in the master page.
I have all my menu options 8 on my master page and they need to be disabled 7 if certain system settings are not set up.
If 6 they are not then a message is displayed 5 and the buttons are disabled. As the settings 4 page is a content page from this master 3 page I don't want the message to keep being 2 displayed on all the settings pages.
this 1 code worked for me:
//Only show the message if on the dashboard (first page after login)
if (this.ContentPlaceHolder1.Page is Dashboard)
{
//Show modal message box
mmb.Show("Warning Message");
}
Use the Below code.
Page.ToString().Replace("ASP.","").Replace("_",".")
0
Here is my solution to the problem (this 3 code goes into the code behind the master 2 page):
if (Page.TemplateControl.AppRelativeVirtualPath == "~/YourPageName.aspx")
{
// your code here
}
or a bit more sophisticated, but less 1 readable:
if (Page.TemplateControl.AppRelativeVirtualPath.Equals("~/YourPageName.aspx", StringComparison.OrdinalIgnoreCase))
{
// your code here
}
Request.CurrentExecutionFilePath;
or
Request.AppRelativeCurrentExecutionFilePath;
0
I do something similar to this in a project 6 of mine to dynamically attach css files 5 based on the page being loaded. I just 4 get the name of the file from the request:
this.Request.Url.AbsolutePath
And 3 then extract the file name from there. I'm 2 not sure if this will work if you are doing 1 URL re-writes though.
You can do this by getting the last segmant 1 or the request and I'll be the Form name
string pageName = this.Request.Url.Segments.Last();
if (pageName.Contains("EmployeeTermination.aspx"))
{
}
You can try this one:
<%: this.ContentPlaceHolder1.Page.GetType().Name.Split('_')[0].ToUpper() %>
Put that code within 1 the title
tags of the Site.Master
string s = Page.ToString().Replace("ASP.directory_name_","").Replace("_aspx",".aspx").Replace("_","-");
if (s == "default.aspx")
{ /* do something */ }
0
so many answers I am using
<%if(this.MainContent.Page.Title != "mypagetitle") { %>
<%}%>
this makes it 7 easy to exclude any single page and since 6 your comparing a string you could even prefix 5 pages like exclude_pagetitle and comparing 4 a sub-string of the title. I use this commonly 3 to exclude log in pages from certain features 2 I don't want to load like session timeouts 1 and live chat.
Below code worked like a charmed ..try it 1
string PName = Request.UrlReferrer.Segments[Request.UrlReferrer.Segments.Length - 1];
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.