Calling MasterPage Subroutines from a ContentPage

J

jeffmagill

Is it possible? I haven't been able to find any information about this.
Not on the web, not in books.

Is it possible to call a function or subroutine which is defined in a
MasterPage from it's derivative ContentPage?

Thanks.
Jeff
 
G

Guest

In your aspx add:
<%@ MasterType virtualPath="~/<MasterPageName>.master"%>

Then in its codebehind:
this.Master.MyMethod()

Hope this is what you needed.
 
J

jeffmagill

Thanks for your quick responses!! I'll let you guys know how it turns
out.

You're welcome for point this out. If you want, I can point out more
problems sooner :)

Jeff
 
Joined
Jan 11, 2013
Messages
2
Reaction score
0
I HOPE MY SOLUTION HELPS MANY SEEKING ANSWERS LIKE MYSELF BUT FAILED.
(1) One thing you guys left out in contentpage calling masterpage.
In ContentPage aspx, you cannot add this
<%
@ MasterType virtualpath="~/{Your Masterpage}.Master" %>
When compile, you get compiler error
So, dont add!
(2) Calling a Public Routine (Property or Function) that is in Masterpage
In Content Page:
just write code as
CType
(Master, {Your MasterPage Name}).{Your MasterPage.PublicRoutine)

That's all. However, do note that inside masterpage page_load,what you declared here will return empty in your calling.

 
Joined
Jan 11, 2013
Messages
2
Reaction score
0
IN ADDITION TO MY COMMENTS:
(1)When contentpage is called, masterpage will load next. So....
In ContentPage Page_load, When you reference a masterpage routine, you may get empty result because the Masterpage.pageload is loaded second.
Hence, whatever variables you assigned value is not captured yet.

Again, just write as:
Dim a as string
a = CType(Master, {Your MasterPage Name}).{Your MasterPage.PublicRoutine)

Hope I helped someone.

Cheers,
Tuck
june1629 at yahoo dot come
 

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,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top