473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Invalid cast of master page class

I have a page Default.aspx. Its first line is the following:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="default.aspx.cs"
Inherits="MyCompany.MyApp.default" Title="Untitled Page" %>

The first line in MasterPage.master is the following:

<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="MasterPage.master.cs" Inherits="MyCompany.MyApp.masterpage" %>

In the MasterPage.master.cs file I am declaring a public property as follows:

public MyCompany.MyApp.Controls.RelatedMenu MenuRelated
{
get { return this.RelatedMenu1; }
}
In the default.aspx.cs in Page_Load method I have the following line:

((masterpage)this.Master).MenuRelated.MenuItems = "select~add";

Some times (not always) this line throws an InvalidCastException and its
message says
Unable to cast ASP.masterpage_master to MyCompany.MyApp.masterpage

Any ideas why?

Thanks
Oct 4 '06 #1
2 3811
I'm encountering the same problem...

It is only occurring on a page utilising a nested master page. Are you
using a nested master page ?

This problem is very strange because I find that the problem seems to
be coming and going without changing any code. I think the problem is
arising when I make changes to other pages (other than the page with
the problem) and then click refresh in the browser without recompiling.
If I go into Visual Studio do a full rebuild and redeploy.... the
problem is gone and the this.Master property can suddenly be cast again
to my nested master page type (without a single line of code being
changed).

I can't think this can be anything other than a bug in the Framework.

As a work around I'm considering not using nested master pages and
simply duplicating the parent master and making modifications to it
(yuck! kind of defeating the whole point of creating master pages).

Can anyone offer me an explanation or a better work around ?
Argirop wrote:
I have a page Default.aspx. Its first line is the following:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="default.aspx.cs"
Inherits="MyCompany.MyApp.default" Title="Untitled Page" %>

The first line in MasterPage.master is the following:

<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="MasterPage.master.cs" Inherits="MyCompany.MyApp.masterpage" %>

In the MasterPage.master.cs file I am declaring a public property as follows:

public MyCompany.MyApp.Controls.RelatedMenu MenuRelated
{
get { return this.RelatedMenu1; }
}
In the default.aspx.cs in Page_Load method I have the following line:

((masterpage)this.Master).MenuRelated.MenuItems = "select~add";

Some times (not always) this line throws an InvalidCastException and its
message says
Unable to cast ASP.masterpage_master to MyCompany.MyApp.masterpage

Any ideas why?

Thanks
Oct 5 '06 #2
No, I am not using nested master pages. In fact the entrire application is
using only one master page. So eliminating the parent master, might not solve
the problem.

"mi******@gmail.com" wrote:
I'm encountering the same problem...

It is only occurring on a page utilising a nested master page. Are you
using a nested master page ?

This problem is very strange because I find that the problem seems to
be coming and going without changing any code. I think the problem is
arising when I make changes to other pages (other than the page with
the problem) and then click refresh in the browser without recompiling.
If I go into Visual Studio do a full rebuild and redeploy.... the
problem is gone and the this.Master property can suddenly be cast again
to my nested master page type (without a single line of code being
changed).

I can't think this can be anything other than a bug in the Framework.

As a work around I'm considering not using nested master pages and
simply duplicating the parent master and making modifications to it
(yuck! kind of defeating the whole point of creating master pages).

Can anyone offer me an explanation or a better work around ?
Argirop wrote:
I have a page Default.aspx. Its first line is the following:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="default.aspx.cs"
Inherits="MyCompany.MyApp.default" Title="Untitled Page" %>

The first line in MasterPage.master is the following:

<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="MasterPage.master.cs" Inherits="MyCompany.MyApp.masterpage" %>

In the MasterPage.master.cs file I am declaring a public property as follows:

public MyCompany.MyApp.Controls.RelatedMenu MenuRelated
{
get { return this.RelatedMenu1; }
}
In the default.aspx.cs in Page_Load method I have the following line:

((masterpage)this.Master).MenuRelated.MenuItems = "select~add";

Some times (not always) this line throws an InvalidCastException and its
message says
Unable to cast ASP.masterpage_master to MyCompany.MyApp.masterpage

Any ideas why?

Thanks

Oct 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Karl Seguin | last post by:
Our website occasionally throws the following exception: at System.Web.UI.Page.LoadPageViewState() at System.Web.UI.Page.ProcessRequestMain() Specified cast is not valid. So far no pattern or...
4
by: Rik Brooks | last post by:
OK, now I'm getting excited. I actually created a master page and added two content place holders to it. I also added a label which will serve as a sort of one line help and a little image button...
8
by: PJ | last post by:
How can I get a reference to the master page class? It is defined as a partial class, but I cannot seem to type a variable to the name of the partial class? The compiler continually shows "The...
4
by: Bob | last post by:
In ASP.NET 1.1, I have a base page for all my pages in an application. The base page contains some common properties that every page needs, the code behind file of every page looks like this: ...
3
by: ivanpais | last post by:
Hi, I have a Web User Control, Lets say "Foo.ascx", that contains a button "btnFoo". I have a Master Page "Bar.master", that has a label "lblBar". This label is exposed by a public property...
3
by: Managed Code | last post by:
I have a BasePage class that derives from System.Web.UI.Page. All of my content pages derive from this. The derived page classes use the following MasterType declaration that follows to reference...
2
by: archana | last post by:
Hi all, i have one master page having one lable control. I want to update content of that lable through content page. I tried to find it using Master properly but of no luck. can anyone...
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
1
by: Ned White | last post by:
Hi, How can I access the Master Page's public methods from a web user control ? Inside the user control, i can see the Page.Master using the this.Page.Master. However it does not seem to be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.