views:

87

answers:

2

Hi All,
I am writing an ASP.Net application. I am making use of master page in it. I have several child pages with me, which consist of some java script functions;
Let's say;

function ChildPageFunction()
{
   //Do something;
}


And master page java script function as;

function MasterPagefunction()
{
   //Need to call ChildPagefunction(); here
}


Now is it possible to call ChildPageFunction() from MasterPageFunction() ?

Please help me if anyone knows how to do this. Thanks in advance.

+1  A: 

Yes. Just call ChildPageFunction(); from anywhere on the MasterPage and it will fire.

function MasterPagefunction()
{
   ChildPagefunction(); // Will work fine
}

This works the other way around to, so you can call MasterPageFunction() from your child page and it will also ifre.

This is because, when rendered, all of the master page html and the child page's html are combined, so both pages share the same JavaScript.

The MasterPage is a template that wraps around your Content Page.

GenericTypeTea
Ohhh why I didn't thought of this ? :)thanks a lot..It worked..
Vijay Balkawade
No worries Vijay.
GenericTypeTea
+1  A: 

It is just javascript, once it is rendered to the browser it has no knowledge of whether it is from the master page or the content page. Just call it normally.

Ben Robinson
Thanks Ben :)It worked for me as a normal java script.
Vijay Balkawade