views:

36

answers:

1

I've created a simple placeHolder for some extra javascript in jQuery - The issue is that the placeHolder is within some script tags and therefore isn't recognized by Sharepoint designer.

The page works correctly, so it hasn't bothered me until now, since you can't touch any part of the design view, without fixing the issue.

My code looks something like this in the master template:

<script type="text/javascript>
  $(document).ready(function(){ 
    <asp:ContentPlaceHolder id="PlaceHolderjQuery" runat="server" />
  });
</script>

Is there a way to make this work correctly, so that the placeholder is actually recognized by Sharepoint Designer?

Thanks for the help!

+2  A: 

I understood that you are trying to call a JavaScript function that is defined inside the PlaceHolder. But your code wont work as the PlaceHolder is a Server Control and pushing it as a child element of the some other tag wont work. Script tag is a client processing tag. So What I would suggest is to change the logic as below.

In the master page I will have a JavaScript to call a function by default.

<script type="text/javascript>
  $(document).ready(function(){ 
       myOnLoadFunction();
  });
</script>

And I will define the content Place Holder with a dummy function

<asp:ContentPlaceHolder id="PlaceHolderjQuery" runat="server">
 <script type="text/javascript>function myOnLoadFunction(){ //do nothing }</script>
</asp:ContentPlaceHolder>

Now in your content page you can define

<asp:Content ID="javascript" ContentPlaceHolderID="PlaceHolderjQuery" runat="server">
 <script type="text/javascript>function myOnLoadFunction(){ alert('Hello jQuery');   }</script>
</asp:Content>
Kusek
Yup that's how I had it before - I liked the other way better, since it was allowing for a cleaner look in a way.The template still works, just sharepoint designer refuses to see the valid PlaceHolderjQuery tag in the middle of the script tag.Thanks for taking the time to propose an alternate solution.
TeckniX
@TeckniX I see what you are saying
Kusek
I'll mark this as the answer - Just in case people check out the code, you're missing some <script></script> tags around the function myOnLoadFunction()Thanks again!
TeckniX
Thanks I have corrected the code with the Script Tag.
Kusek