pageLoad function in page and masterpage

2.2k views Asked by At

I'm trying to use function pageLoad() (asp.net related JS event)

I have one in the masterpage, and one in a different page. For some reason they don't want to be friends... only one is called.

When I cancel one, the other one is called so I don't see a problem there...

Any idea?

Master page:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="....." Inherits="......." %>



<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

    <script>
        function pageLoad() {
            alert('masterpage load');
            CallStyledArrowSelect();

        }
    </script>


      //more irrelevant code

 <asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>

And in the content page:

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script>
   function pageLoad(){
     alert('hi i'm not working');
}
//more code...
1

There are 1 answers

0
Ziv Weissman On BEST ANSWER

OK,

thanks to andrey.shedko for the link,

Apparently it is not possible to have 2 pageLoad functions - one in the masterpage and one in the content page. The solution suggested there is making another function on the content page and call it if it exist:

function pageLoad() {
    // Master pageLoad() code.

    // If function contentPageLoad exists, execute it.
    if(typeof contentPageLoad == 'function')
      contentPageLoad();
}