From: Tom Becker on
Hallo

I'm trying to access some public functions of a master page from a
content page.

Casting a base masterpage to a specific one (that contains my functions)
results in a runtime error:

protected void Page_Load(object sender, EventArgs e)
{
MyNameSpace.MasterPages.Main temp = Master as
MyNameSpace.MasterPages.Main;

Debug.Assert(temp != null, "Error casting");

temp.DoSomething();

...
}

I googled the error and it seems that the same issue occurs more than
once. There is also a bugfix from Microsoft "NDP20-KB915782-X86.exe"
but I can't install it.

Using
<%@ MasterType VirtualPath="~/MasterPages/Main.Master"%>
doesn't solve the problem either as the compiler just overwrites
the Master-property.

BTW I'm using Visual Studio 2008 sp1 and .net3.5 SP1


Any suggestions?
Tom


From: Alexey Smirnov on
On May 3, 2:45 pm, Tom Becker <tdotbeckeratapedotde> wrote:
> Hallo
>
> I'm trying to access some public functions of a master page from a
> content page.
>
> Casting a base masterpage to a specific one (that contains my functions)
> results in a runtime error:
>
> protected void Page_Load(object sender, EventArgs e)
> {
>    MyNameSpace.MasterPages.Main temp = Master as
>    MyNameSpace.MasterPages.Main;
>
>    Debug.Assert(temp != null, "Error casting");
>
>    temp.DoSomething();
>
>    ...
>
> }
>
> I googled the error and it seems that the same issue occurs more than
> once. There is also a bugfix from Microsoft "NDP20-KB915782-X86.exe"
> but I can't install it.
>
> Using
> <%@ MasterType VirtualPath="~/MasterPages/Main.Master"%>
> doesn't solve the problem either as the compiler just overwrites
> the Master-property.
>
> BTW I'm using Visual Studio 2008 sp1 and .net3.5 SP1
>
> Any suggestions?
> Tom

Well, I think your code looks correct. If I were you I would try to
make a simple test with new master and content page to see if you can
reproduce the issue. Maybe it's a kind of naming problem or something
like this.