wsyeager Posted January 12, 2006 Posted January 12, 2006 (edited) I'm getting the above error when running through my code. I know at desgin time what the problem is, but at run time I'm changing the MasterPage to use with a specific aspx page in the Page_PreInit event. If I could solve the design time compile error, I'm hoping it will fix the run-time error. I have code in my code-behind file that looks like the following: Public WithEvents objMaster As MasterPage 'Get a reference to the master page objMaster = DirectCast(Me.Master, MasterPage) 'Add the section and get a treeview back objMaster.AddCustomSection(2, "Folders") Protected Sub Page_PreInit1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit If Session.Item("EPPMasterPageFile") IsNot Nothing Then Me.MasterPageFile = Convert.ToString(Session.Item("EPPMasterPageFile")) Else Me.MasterPageFile = "~/MasterPage.master" End If End Sub The boldfaced line above has a design time compile error in it.stating that "AddCustomeSection is not a member of 'System.Web.UI.MasterPage". When I have the MasterPageFile property of the aspx page at design time set to a master page (which is contained inside the Sessin variable), "MasterPageFile="~/Platform/EPP/Portfolio/EPPMasterPage.master", that's when the compile error occurs. I have the following section inside the above masterpage: Public Sub AddCustomSection(ByVal Index As Integer, ByVal Title As String) Dim objCustomSection As New CustomSection objCustomSection.Index = Index objCustomSection.Title = Title objCustomSections.Add(objCustomSection) End Sub As you can see, the sub is public and should be able to be seen by my code behind file with the intellisense. Now, bearing the above in mind, when I change the MasterPageFile property of the aspx page at design time to the main master page (on the root of the website), with the same code above (the main one has the Sub in it as well), I do not get a design time compile error! The application runs and changes the master pages successfully with no problem, except when I click on a link that needs the code above (inside the masterpage, which is not on the root). Note that these masterpages are not related, and they are not in a parent/child relationship. Does anybody know what the problem is? Edited January 12, 2006 by PlausiblyDamp Quote Thanks, Bill Yeager (MCP, BCIP) Microsoft Certified Professional Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer YeagerTech Consulting, Inc.
Administrators PlausiblyDamp Posted January 12, 2006 Administrators Posted January 12, 2006 The builtin class MasterPage is a class that other MasterPages inherit from and does not contain a definition for your AddCustomSection method. Rather than casting the MaterPage property to a MasterPage (which it already is) like you are doing with objMaster = DirectCast(Me.Master, MasterPage) you will need to declare it and cast it to the correct type Dim objMaster as EPPMasterPage 'Or whatever the name of the class for your master page is. objMaster = DirectCast(Me.Master, EPPMasterPage) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
wsyeager Posted January 12, 2006 Author Posted January 12, 2006 Thanks. that was it.... Quote Thanks, Bill Yeager (MCP, BCIP) Microsoft Certified Professional Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer YeagerTech Consulting, Inc.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.