locked
Where to put the AJAX script manager RRS feed

  • Question

  • User-1312231374 posted

    I am using Asp.Net VB.  I am not using a master page.

    Where is the best place to put the script manager?  Top or bottom? Does either impact page loading speed?

    Also, can it be in a div? (Not that I need it there...just curious.)

    Thank you,

    Thor

    Wednesday, February 11, 2015 2:45 PM

Answers

  • User2103319870 posted

    Top or bottom?

    You need to put it on Top, By the word Top I mean to say you should add the ScriptManager before you add any controls which internally uses the scriptmanager.

    Like for example UpdatePanel control

    <asp:ScriptManager ID="ScriptManager" 
                       runat="server" />
    <asp:UpdatePanel ID="UpdatePanel1" 
                     UpdateMode="Conditional"
                     runat="server">
        <ContentTemplate>
           <fieldset>
           <legend>UpdatePanel content</legend>
            <!-- Other content in the panel. -->
            <%=DateTime.Now.ToString() %>
            <br />
            <asp:Button ID="Button1" 
                        Text="Refresh Panel" 
                        runat="server" />
            </fieldset>
        </ContentTemplate>
    </asp:UpdatePanel>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 11, 2015 2:53 PM
  • User-1312231374 posted

    I appreciate the answer and I understand that with the update panel, the script manager would have to be at the top.  

    However, I am using it with other tools (TextBoxWatermarkExtender) for example.  There, it works at the bottom because it does not care where the extender is placed as long as it is after the script manager.

    I am probably making too big a deal out of this, but I am still curious if the page will load faster if it does not have to read the ajax script first.  Do you know if this matters?

    Thanks,

    Thor

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 11, 2015 6:30 PM
  • User555306248 posted

    Refer LoadScriptsBeforeUI property -

    The LoadScriptsBeforeUI property determines how scripts in the Scripts collection are loaded relative to the markup for the page UI.

    When the LoadScriptsBeforeUI property is true, a script element is rendered before the page's UI markup is loaded. In this scenario, if UI elements are defined in scripts, the UI will be fully functional when it loads. However, if the script accesses UI elements in the markup for which instances have not yet been created, an error might occur. To make sure that UI elements are loaded before you access them, handle the load event of the Sys.Application class.

    When the LoadScriptsBeforeUI property is false, a script element is rendered after the page's UI markup is rendered. In this scenario, the UI loads more quickly, but it might not be fully functional if scripts that define additional UI elements have not finished loading.

    https://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.loadscriptsbeforeui(v=vs.110).aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 11, 2015 11:12 PM
  • User-1312231374 posted

    This is great stuff.  Thank you!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 12, 2015 11:04 AM

All replies

  • User2103319870 posted

    Top or bottom?

    You need to put it on Top, By the word Top I mean to say you should add the ScriptManager before you add any controls which internally uses the scriptmanager.

    Like for example UpdatePanel control

    <asp:ScriptManager ID="ScriptManager" 
                       runat="server" />
    <asp:UpdatePanel ID="UpdatePanel1" 
                     UpdateMode="Conditional"
                     runat="server">
        <ContentTemplate>
           <fieldset>
           <legend>UpdatePanel content</legend>
            <!-- Other content in the panel. -->
            <%=DateTime.Now.ToString() %>
            <br />
            <asp:Button ID="Button1" 
                        Text="Refresh Panel" 
                        runat="server" />
            </fieldset>
        </ContentTemplate>
    </asp:UpdatePanel>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 11, 2015 2:53 PM
  • User-1312231374 posted

    I appreciate the answer and I understand that with the update panel, the script manager would have to be at the top.  

    However, I am using it with other tools (TextBoxWatermarkExtender) for example.  There, it works at the bottom because it does not care where the extender is placed as long as it is after the script manager.

    I am probably making too big a deal out of this, but I am still curious if the page will load faster if it does not have to read the ajax script first.  Do you know if this matters?

    Thanks,

    Thor

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 11, 2015 6:30 PM
  • User555306248 posted

    Refer LoadScriptsBeforeUI property -

    The LoadScriptsBeforeUI property determines how scripts in the Scripts collection are loaded relative to the markup for the page UI.

    When the LoadScriptsBeforeUI property is true, a script element is rendered before the page's UI markup is loaded. In this scenario, if UI elements are defined in scripts, the UI will be fully functional when it loads. However, if the script accesses UI elements in the markup for which instances have not yet been created, an error might occur. To make sure that UI elements are loaded before you access them, handle the load event of the Sys.Application class.

    When the LoadScriptsBeforeUI property is false, a script element is rendered after the page's UI markup is rendered. In this scenario, the UI loads more quickly, but it might not be fully functional if scripts that define additional UI elements have not finished loading.

    https://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.loadscriptsbeforeui(v=vs.110).aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 11, 2015 11:12 PM
  • User-1312231374 posted

    This is great stuff.  Thank you!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 12, 2015 11:04 AM