MVC, nested masterpage and Javascript

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
 
M

Mark Banfill

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
 
B

bruce barker

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)
 
M

Mark Banfill

I solved my problem. Javascript links need to be adjusted and added again to
the head section of the nested masterpage.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top