Access method in master's master

J

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.
 
B

bruce barker

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)
 
J

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
 
J

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
 
J

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top