Solved

Get name of master page in asp.net

Posted on 2008-06-13
3
849 Views
Last Modified: 2008-06-21
asp.net  3.5 with vb

My issue seems quite simple but am having some probems.

I have a master page with a number of child pages.

When a page loads and is based on the top level master page, I want to run code in the page load event.  If a page is based on any of the child masters then I do not want to run the code.

I thought a simple bit of code as below (pseudo code) in page_load woud do the trick:

if currentpage.masterpagefile = "mypage.master" then
run code
end if

If I could get the name of the current page master file then I would be fine but am not managing to do this.

Anyone know how this can be done

Wing
0
Comment
Question by:WingYip
[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
3 Comments
 
LVL 7

Expert Comment

by:skiltz
ID: 21782223
that works fine for me....

have you tried outputting the name ie response.write(me.masterpagefile.toString())

I have a masterpage called site.master and the output in my case was /site.master
0
 
LVL 1

Author Comment

by:WingYip
ID: 21782333
I realise I've put the code in the top level master page itself.  Is this not the way to do it.  I assumed taht the code would execute in the context of the content page but perhaps not.  Will I have to create a class and refer to it from all pages where I want the code executed I wonder?

Wing
0
 
LVL 1

Accepted Solution

by:
WingYip earned 0 total points
ID: 21783212
Sorted it.

I should be writing

me.page.masterpagefile

me.masterpagefile doesnt seem to work...

Am going for points refund

Cheers for input

Wing
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

752 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