Share via


Getting Started with Script Manager and UpdatePanel

Question

Tuesday, December 14, 2010 11:37 AM

Hi,I am looking at using asp.net for a project but am hitting a bit of a problem, I have a script manager in my master file(Site1.master)
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
            </asp:ScriptManager>
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
and want to use an UpdatePanel in another file (WebForm1.aspx)
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        </asp:UpdatePanel>
</asp:Content>
in WebForm1.aspx.cs I have
        protected void Page_Load(object sender, EventArgs e)
        {
            ScriptManager scriptManager = ScriptManager.GetCurrent(this);
        }
but when i try to run I get the error
The control with ID 'UpdatePanel1' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.
any idea how I can get around this, i was under the impression that I should create my ScriptManager in Site1.master and call ScriptManager.GetCurrent(this); to use it in other files but I cant get it to work.
Thanks,Eamonn

<body>

    <form id="form1" runat="server">

    <div>

        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

            <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">

            </asp:ScriptManager>

        </asp:ContentPlaceHolder>

    </div>

    </form>

</body

<body>
    <form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
            </asp:ScriptManager>
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>

All replies (3)

Tuesday, December 14, 2010 10:10 PM ✅Answered

since the scriptmanager is on the master page, you would need to add a scriptmanagerproxy to each aspx page that uses ajax controls.

The script manager adds javascript to the page. HTML pages work from a top down order. If you Ajax control needs to access a javascript method (which they all do, because Ajax is always using javascript to be true Ajax), then the javascript must be before the Ajax control renders.

My recommendation is to add the script manager in the CreateChildControls method of your webpart right before you create your Ajax controls.

Here is the microsoft example of this: http://msdn.microsoft.com/en-us/library/bb862184.aspx. This example is showing the UpdatePanel fix, but the concept is the same - they add the scrip manager programatically right before they add the other controls in the CreateChildControls. Also, notice their comment in code "//The ScriptManager control must be added first."

Hope this helps.


Thursday, December 16, 2010 1:19 AM ✅Answered

Hi,

By default, the ScriptManager control registers the script for the Microsoft Ajax Library with the page. This enables client script to use the Microsoft Ajax type system extensions and to support features such as partial-page rendering and Web-service calls. In addition, the ScriptManager control enables the Microsoft Ajax Library to be loaded from the Microsoft Content Delivery Network (CDN).

ASP.NET UpdatePanel controls enable you to build rich, client-centric Web applications. By using UpdatePanel controls, you can refresh selected parts of the page instead of refreshing the whole page with a postback. This is referred to as performing a partial-page update. An ASP.NET Web page that contains a ScriptManager control and one or more UpdatePanel controls can automatically participate in partial-page updates, without custom client script.

For more details, please refer to:http://msdn.microsoft.com/en-us/library/bb386522.aspx.


Tuesday, December 14, 2010 3:18 PM

does your WebForm1.aspx inherit Site1.Master?

your aspx page should be similir to:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.master" AutoEventWireup="true"
    CodeFile="WebForm1.aspx.cs" Inherits="WebForm1_Class" %>