MVC, nested masterpage and Javascript

  • Thread starter Thread starter Tommy Jakobsen
  • Start date Start date
T

Tommy Jakobsen

Hi.

Is there a problem when trying to use Javascript on a nested masterpage?

On my masterpage, i've got this in the <head>:
<asp:ContentPlaceHolder ID="HeadContent" runat="server" />

And on the nested masterpage:
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<asp:ContentPlaceHolder ID="NestedHeadContent" runat="server" />
</asp:Content>

And on my content page page:
<asp:Content ID="Content1" ContentPlaceHolderID="NestedHeadContent"
runat="server">
... .js includes goes here ...
<script type="text/javascript">
$(function()
{
$('.startDate-pick').datePicker({startDate:'01/01/1996'});
});
</script">
</asp:Content>

And in the body of the nested page, i've got this input field with the class
used above:
<input id="startDate" name="startDate" type="text" size="7"
class="startDate-pick" />


This works on content pages within the masterpage, but not on content pages
within the nested masterpage. Why is that, and what can I do about it?

Thanks in advance.

Tommy
 
Hi,

I've also got this problem. Has anybody successfully used jQuery on a nested masterpage?

Thanks,

Mark



Tommy Jakobsen wrote:

MVC, nested masterpage and Javascript
13-Sep-08

Hi

Is there a problem when trying to use Javascript on a nested masterpage

On my masterpage, i've got this in the <head>
<asp:ContentPlaceHolder ID="HeadContent" runat="server" /

And on the nested masterpage
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"
<asp:ContentPlaceHolder ID="NestedHeadContent" runat="server" /
</asp:Content

And on my content page page
<asp:Content ID="Content1" ContentPlaceHolderID="NestedHeadContent
runat="server"
... .js includes goes here ..
<script type="text/javascript"
$(function(

$('.startDate-pick').datePicker({startDate:'01/01/1996'})
})
</script"
</asp:Content

And in the body of the nested page, i've got this input field with the clas
used above
<input id="startDate" name="startDate" type="text" size="7
class="startDate-pick" /

This works on content pages within the masterpage, but not on content page
within the nested masterpage. Why is that, and what can I do about it

Thanks in advance

Tommy

EggHeadCafe - Software Developer Portal of Choice
SEO With Google, MSN, and Yahoo Site: and Link: counts
http://www.eggheadcafe.com/tutorial...e2f-d7d870642c44/seo-with-google-msn-and.aspx
 
you are trying to attach the picker before the input control is
rendered, so the $('.startDate-pick') returns an empty query. attach at
dom ready (jquery start):

$(function() {
$('.startDate-pick')
.datePicker({startDate:'01/01/1996'});
});

-- bruce (sqlwork.com)
 
I solved my problem. Javascript links need to be adjusted and added again to
the head section of the nested masterpage.
 
Back
Top