Access method in master"s master

Access method in master"s master

am 24.01.2008 13:47:55 von John

Hi there,

I'm trying to access a method in a nested master, so far without much
success.

The structure is as follows:

'Main master' (containing public menu setting method) is master to 'Sub
master', both of which are at the site root. The 'Sub master' is master to
'Content page' in a folder.

Master.SetMenu("Products") - works if just used on a test content page at
the root, but...
Master.Master.SetMenu("Products") - fails with an error saying 'SetMenu' is
not a member of 'System.Web.UI.MasterPage'. I understand the error, but how
can I access a method in a master's master?

Thanks

John

PS - I'm using <%@ MasterType VirtualPath="~/Sub.master" %> (and
"~/Main.master") in the respective masters.

RE: Access method in master"s master

am 24.01.2008 17:29:04 von brucebarker

you should define an interface (in app_code) that the master implement, then
your code can cast the Master to the interface:

in app_code:

public interface ISetMenu { void SetMenu(string name)}

then implement in your master:

public partial class MainMasterPage : System.Web.UI.MasterPage, ISetMenu
{
}

then call:

((ISetMenu) Master.Master).SetMenu("Products");



-- bruce (sqlwork.com)


"John" wrote:

> Hi there,
>
> I'm trying to access a method in a nested master, so far without much
> success.
>
> The structure is as follows:
>
> 'Main master' (containing public menu setting method) is master to 'Sub
> master', both of which are at the site root. The 'Sub master' is master to
> 'Content page' in a folder.
>
> Master.SetMenu("Products") - works if just used on a test content page at
> the root, but...
> Master.Master.SetMenu("Products") - fails with an error saying 'SetMenu' is
> not a member of 'System.Web.UI.MasterPage'. I understand the error, but how
> can I access a method in a master's master?
>
> Thanks
>
> John
>
> PS - I'm using <%@ MasterType VirtualPath="~/Sub.master" %> (and
> "~/Main.master") in the respective masters.
>
>
>
>
>
>
>

Re: Access method in master"s master

am 24.01.2008 19:33:40 von John

Hello Bruce,

Thanks for your reply. I think I understand. I'll decode into vb and have
a go.

Thanks again.

Best regards

John


"bruce barker" wrote in message
news:F58B47C0-C3A9-4319-86DA-528FBABE4B71@microsoft.com...
> you should define an interface (in app_code) that the master implement,
> then
> your code can cast the Master to the interface:
>
> in app_code:
>
> public interface ISetMenu { void SetMenu(string name)}
>
> then implement in your master:
>
> public partial class MainMasterPage : System.Web.UI.MasterPage, ISetMenu
> {
> }
>
> then call:
>
> ((ISetMenu) Master.Master).SetMenu("Products");
>
>
>
> -- bruce (sqlwork.com)
>
>
> "John" wrote:
>
>> Hi there,
>>
>> I'm trying to access a method in a nested master, so far without much
>> success.
>>
>> The structure is as follows:
>>
>> 'Main master' (containing public menu setting method) is master to 'Sub
>> master', both of which are at the site root. The 'Sub master' is master
>> to
>> 'Content page' in a folder.
>>
>> Master.SetMenu("Products") - works if just used on a test content page at
>> the root, but...
>> Master.Master.SetMenu("Products") - fails with an error saying 'SetMenu'
>> is
>> not a member of 'System.Web.UI.MasterPage'. I understand the error, but
>> how
>> can I access a method in a master's master?
>>
>> Thanks
>>
>> John
>>
>> PS - I'm using <%@ MasterType VirtualPath="~/Sub.master" %> (and
>> "~/Main.master") in the respective masters.
>>
>>
>>
>>
>>
>>
>>

Re: Access method in master"s master

am 25.01.2008 20:50:18 von John

Hello Bruce,

I'm getting a bit further I think....

I've added the interface to app_code:

'Imports Microsoft.VisualBasic

Public Interface ISetMenu

Sub SetMenu(ByVal strMain As String)

End Interface


.....and amended the MainMaster partial class, but I'm having difficulty with
the content page implementation.

You don't know what the VB.NET version of:

((ISetMenu) Master.Master).SetMenu("Products");

....would be do you? I'm afraid I'm new to c# and interfaces!

Thanks

John



"bruce barker" wrote in message
news:F58B47C0-C3A9-4319-86DA-528FBABE4B71@microsoft.com...
> you should define an interface (in app_code) that the master implement,
> then
> your code can cast the Master to the interface:
>
> in app_code:
>
> public interface ISetMenu { void SetMenu(string name)}
>
> then implement in your master:
>
> public partial class MainMasterPage : System.Web.UI.MasterPage, ISetMenu
> {
> }
>
> then call:
>
> ((ISetMenu) Master.Master).SetMenu("Products");
>
>
>
> -- bruce (sqlwork.com)
>
>
> "John" wrote:
>
>> Hi there,
>>
>> I'm trying to access a method in a nested master, so far without much
>> success.
>>
>> The structure is as follows:
>>
>> 'Main master' (containing public menu setting method) is master to 'Sub
>> master', both of which are at the site root. The 'Sub master' is master
>> to
>> 'Content page' in a folder.
>>
>> Master.SetMenu("Products") - works if just used on a test content page at
>> the root, but...
>> Master.Master.SetMenu("Products") - fails with an error saying 'SetMenu'
>> is
>> not a member of 'System.Web.UI.MasterPage'. I understand the error, but
>> how
>> can I access a method in a master's master?
>>
>> Thanks
>>
>> John
>>
>> PS - I'm using <%@ MasterType VirtualPath="~/Sub.master" %> (and
>> "~/Main.master") in the respective masters.
>>
>>
>>
>>
>>
>>
>>

Re: Access method in master"s master

am 26.01.2008 16:29:43 von John

...OK, have managed to work it out and at least I now understand what c# type
conversion looks like!

For anyone else who's interested the vb is as follows:
CType(Master.Master, ISetMenu).SetMenu("Products")

Thanks again Bruce. Works a treat.

Best regards

John


"John" wrote in message
news:OaOfFu4XIHA.3696@TK2MSFTNGP03.phx.gbl...
> Hello Bruce,
>
> I'm getting a bit further I think....
>
> I've added the interface to app_code:
>
> 'Imports Microsoft.VisualBasic
>
> Public Interface ISetMenu
>
> Sub SetMenu(ByVal strMain As String)
>
> End Interface
>
>
> ....and amended the MainMaster partial class, but I'm having difficulty
> with the content page implementation.
>
> You don't know what the VB.NET version of:
>
> ((ISetMenu) Master.Master).SetMenu("Products");
>
> ...would be do you? I'm afraid I'm new to c# and interfaces!
>
> Thanks
>
> John
>
>
>
> "bruce barker" wrote in message
> news:F58B47C0-C3A9-4319-86DA-528FBABE4B71@microsoft.com...
>> you should define an interface (in app_code) that the master implement,
>> then
>> your code can cast the Master to the interface:
>>
>> in app_code:
>>
>> public interface ISetMenu { void SetMenu(string name)}
>>
>> then implement in your master:
>>
>> public partial class MainMasterPage : System.Web.UI.MasterPage,
>> ISetMenu
>> {
>> }
>>
>> then call:
>>
>> ((ISetMenu) Master.Master).SetMenu("Products");
>>
>>
>>
>> -- bruce (sqlwork.com)
>>
>>
>> "John" wrote:
>>
>>> Hi there,
>>>
>>> I'm trying to access a method in a nested master, so far without much
>>> success.
>>>
>>> The structure is as follows:
>>>
>>> 'Main master' (containing public menu setting method) is master to 'Sub
>>> master', both of which are at the site root. The 'Sub master' is master
>>> to
>>> 'Content page' in a folder.
>>>
>>> Master.SetMenu("Products") - works if just used on a test content page
>>> at
>>> the root, but...
>>> Master.Master.SetMenu("Products") - fails with an error saying 'SetMenu'
>>> is
>>> not a member of 'System.Web.UI.MasterPage'. I understand the error, but
>>> how
>>> can I access a method in a master's master?
>>>
>>> Thanks
>>>
>>> John
>>>
>>> PS - I'm using <%@ MasterType VirtualPath="~/Sub.master" %> (and
>>> "~/Main.master") in the respective masters.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>
>