Exploring the depths and potentials of ASP.NET RSS 2.0 or Subscribe to .BenRush by Email
 Sunday, March 12, 2006

    I was running into some issues trying to get a strongly-typed reference to a master page one of my content pages used; I remember blogging about this at one point in the past, but I want to do it again to remind myself (and anyone else) that may encounter this issue.

    If you want to access your master page in a strongly-typed fashion (without the need for late-binding or reflection), simply add this to your content page's .aspx file:

    <%@ MasterType VirtualPath="<virtual_path_to_your_master_page>.master" %>

    You can then access all the properties, methods, etc. that you have added to your master page without late-binding and other such nasties. Visual Studio can be retarded at times and fall behind in terms of intellisense until you recompile the solution. The end-effect looks like this, then:

    Me.Master.<whatever>()

    An interesting side-effect of this is that if you reference a particular type in your master page file and that isn't referenced by the content page (such as a user control [.ascx file]), you can get a compiler error that looks like this:

Error    1    c:\blah\blah.aspx.vb(23): error BC30652: Reference required to assembly 'App_Web_lyipwsg9, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' containing the type 'blah.blah'. Add one to your project.    c:\blah\blah.aspx.vb    1   


    The reason is you now expose types through get/set properties, return values or parameters utilized by your master page file to the content page. The above compiler error is a bit weird to look at and doesn't make sense at first glimpse. To fix this, reference those types in your content (.aspx) pages the same way you reference them in your master (.master) files.


kick it on DotNetKicks.com
Sunday, March 12, 2006 4:21:19 PM (Central Standard Time, UTC-06:00)  #    Comments [1] - Trackback
Computing
Friday, May 05, 2006 7:38:14 AM (Central Standard Time, UTC-06:00)
Thank you. This error was starting to annoy me ...
Al
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview

Computers Blogs - Blog Top Sites

Archive
<January 2009>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009
Benjamin Rush
Sign In
Statistics
Total Posts: 444
This Year: 0
This Month: 0
This Week: 0
Comments: 128
Themes
Pick a theme:
All Content © 2009, Benjamin Rush
DasBlog theme 'Business' created by Christoph De Baene (delarou)