nptalcott
08-06-2008, 07:42 PM
Hi,
Currently I am working on a menu in a SharePoint site where we are using code to create dropdown menus in some content pages. I did not design this site and the original designer seemed to be happy with anything as long as "it works". This is causing some maintainability problems.
Originally we had the menu working by calling the P7_ExpMenu() function using <body onload=""> in the master page while the definition <script type="text/javascript" language="JavaScript" src="menu.js"><script> was located in the content page. This was causing an error on any content page that didn't use the menu as it didn't have the function definition (but it "worked" because there were no menus on these pages to fail). So, as a temporary fix, I moved the definition into the master page header and everything runs properly with no errors.
The problem is:
In the long term I will have no control over the master page being used so the solution must be confined to the content page. This means moving the definition and onload call from the master to the content page. I've tried doing this using window.onload instead of <body onload=""> as a content page does not have a body tag. My code currently looks like:
.....
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<script type="text/javascript" language="JavaScript" src="menu.js">window.onload=P7_ExpMenu();</script>
.....
This code does not work. Any ideas how I might get this to work without putting code in the master? Is it a problem with where I am invoking the onload call (in PlaceHolderMain)? Is it a problem with the syntax of the call?
I saw another solution where they modify the Page_Load() code behind (.cs) rather than using JavaScript to modify the body tag using the command body.attributes.add("onload","P7_ExpMenu") but I don't know how to do this in SharePoint. Could I just created a .cs file with only the Page_Load() function and put it in the same directory as the content page?
Any help is appreciated,
Nathaniel
Currently I am working on a menu in a SharePoint site where we are using code to create dropdown menus in some content pages. I did not design this site and the original designer seemed to be happy with anything as long as "it works". This is causing some maintainability problems.
Originally we had the menu working by calling the P7_ExpMenu() function using <body onload=""> in the master page while the definition <script type="text/javascript" language="JavaScript" src="menu.js"><script> was located in the content page. This was causing an error on any content page that didn't use the menu as it didn't have the function definition (but it "worked" because there were no menus on these pages to fail). So, as a temporary fix, I moved the definition into the master page header and everything runs properly with no errors.
The problem is:
In the long term I will have no control over the master page being used so the solution must be confined to the content page. This means moving the definition and onload call from the master to the content page. I've tried doing this using window.onload instead of <body onload=""> as a content page does not have a body tag. My code currently looks like:
.....
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<script type="text/javascript" language="JavaScript" src="menu.js">window.onload=P7_ExpMenu();</script>
.....
This code does not work. Any ideas how I might get this to work without putting code in the master? Is it a problem with where I am invoking the onload call (in PlaceHolderMain)? Is it a problem with the syntax of the call?
I saw another solution where they modify the Page_Load() code behind (.cs) rather than using JavaScript to modify the body tag using the command body.attributes.add("onload","P7_ExpMenu") but I don't know how to do this in SharePoint. Could I just created a .cs file with only the Page_Load() function and put it in the same directory as the content page?
Any help is appreciated,
Nathaniel