views:

288

answers:

1

hi

i am using the clientscript.registerclientscriptblock with (typeof(page),this,that) to bung in my scripts.. ie. jquery and validate etc..

and i also have some hand scripted stuff in the head (where scripts are supposed to be .. right?) doing bits and bobs..

but it seems that as the registerclientscript doesnt put the scripts in the head (goodness knows why) that the scripts i have put in by hand in the head!

surely .net has a way to put the scipts in the head..?! no?!? or am i going to have to either, dump all my hand coded stuff at the bottom of all my pages (just feels all wrong) or .. is there another answer?

thanks

nat

i truly cannot understand why the registerscriptblock/include does not put things in the head of the page... why why why - ok im sure there is a reasonable answer, but even so ?

A: 

If you're using master pages, the job is as simple as this...

<!-- in master page -->
<head>
    <link type="text/css" rel="stylesheet" href="/styles/common1.css" />
    <script type="text/javascript" src="/scripts/common1.js"></script>
    <asp:contentplaceholder id="ExtraStylesAndScripts" runat="server" />
</head>

<!-- on child pages -->
<asp:content contentplaceholderid="ExtraStylesAndScripts" runat="server">    
    <link type="text/css" rel="stylesheet" href="/styles/extra1.css" />
    <script type="text/javascript" src="/scripts/extra1.js"></script>
</asp:content>

Here's a link about custom header elements in ASP.NET

Josh Stodola
hi, thanksi was trying to avoid that. but maybe ill have to go through the many pages and do that.. not using master pages for these onesmost annoying
nat
Sorry, it is the only way. I guess I don't see why it is so crucial for your scripts to be in the `<head>` section anyways.
Josh Stodola
its because the scripts i am adding via the register function are the jquery libs and the like.. and the pages themselves have their own functions.. that are using the libraries in the head. so none of them run, as the libraries are included below. which doesnt work.thanks for your suggestion though, will be making master pages for all these pages as soon as i get enough time.. clear my todo's
nat