Using javascript on pages that use a master page

Last post 12-02-2009 7:43 PM by OlivierStorm. 3 replies.

Sort Posts:

  • Using javascript on pages that use a master page

    11-19-2007, 10:37 AM

    I was wondering if i could get any guidance on using javascript for pages that make use of a masterpage. To give a specific example i would like to implement the delay load described by Matt Berseth here: http://mattberseth.com/blog/2007/07/delay_load_an_updatepanel.html. In the example he implements a lot of javascript that is specific to the page so i don't think it makes sense to add it to a script library. But how do i use it in a page inherited from a master page. The js is specific to the content of the page so i would not want to put it in the master page and you can't add a <script> </script> to content pages. It als seems tedious to use a stringbuilder and registerclientscriptblock from the code-behind (seems like i remember reading that this could be a problem with Ajax enabled pages anyway). So how are people managing ajax w/ custom js in content pages? Any pointers greatly appreciated.

     

    Thanks,

    Kevin

  • Re: Using javascript on pages that use a master page

    11-19-2007, 11:01 AM
    Answer

    Kevin.McPhail:
     and you can't add a <script> </script> to content pages.

    You most certainly can!  Typically I place it right after the <asp:Content> tag at the top of the page.  Just a few things to remember, if you are going to reference server controls in your javascript, use the client ID to reference the control such as:

        document.getElementById('<%= MyControl.ClientID %>').value

    rather than

        document.getElementByID('MyControl').value.

    Because IDs get mangled/changed a bit by the master/content system.  Also, if you have a scriptmanager or scriptmanagerproxy on your content page, place your scripts after that.

    When you ask a question, remember to click "mark as answered" when you get a reply which answers your question.


    My latest ASP.NET AJAX blog entries.
  • Re: Using javascript on pages that use a master page

    11-19-2007, 3:09 PM

    Holy smokes! I feel like an idiot. Can't believe i did not try that before posting.

  • Using javascript on pages that use a master page

    12-02-2009, 7:43 PM
    • Member
      21 point Member
    • OlivierStorm
    • Member since 10-29-2009, 9:14 AM
    • Posts 8

    I  am adding a great link for any of you looking for solutions 

    - masterpage

    - contentplaceholder

    - javascript  


    http://www.dotnetcurry.com/ShowArticle.aspx?ID=273


    All the merits for Mr Suprotim Agarwal

    and I didn't find his artikel over here....

Page 1 of 1 (4 items)