How to call javascript function of child page from javascript main page


I am writing an ASP.Net application. I use the main page in it. I have several child pages with me, which consist of some java script functions; Say;

function ChildPageFunction() { //Do something; } 


And the main page is java script function as;

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


Now you can call ChildPageFunction () from MasterPageFunction ()?

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

+6
javascript parent-child master-pages
source share
2 answers

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

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

This works the other way around, so you can call MasterPageFunction() from your child page, as well as ifre.

This is due to the fact that when rendering, all the html of the main page and the html of the child page are combined, so both pages have the same JavaScript.

MasterPage is a template that wraps around your content page.

+2
source share

This is just javascript, once it is displayed in the browser, it does not know whether it is on the main page or on the content page. Just call normally.

+2
source share

All Articles