Pergunta

I have been dealing with an unusual set of errors when I try to compile my asp.net page. This page is inheriting from my masterpage. It should be getting the Scriptmanager from there. But the errors I am getting suggest that it is not.

Now I have this in my page:

    <%@ Page Title="MassUpdate" Language="C#"
         MasterPageFile="~/Site1.Master"
         AutoEventWireup="true"
         CodeBehind="Update.aspx.cs"
         Inherits="AdminSite.Update"
         MaintainScrollPositionOnPostback="true" %>


     <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server" >

        <div id="contentarea">
            <div>
                <h3 style="color:Red; padding-left:5px;">
                    WARNING - This page can push large amounts of data into the database. Use care when using it!
                </h3>
            </div>    


        <asp:ScriptManagerProxy runat="server"  >

        </asp:ScriptManagerProxy>

And in my masterpage, I have this:

<body>
    <header>
       <div id="banner">

            <h1 style="color:#DBFFFF">UAC Parts Admin</h1>    
    </div>
</header>
<form id="form1" runat="server">

<div id="container">

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


    </asp:ContentPlaceHolder>
    <asp:LoginView ID="LoginView1" runat="server" EnableViewState="false">
        <LoggedInTemplate>
      <div id="menubar">

        <h6>Reports</h6>
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
                <Scripts>
                    <asp:ScriptReference Path="~/Scripts/jquery.js" />
                    <asp:ScriptReference Path="~/Scripts/jqueryui.js" />
                    <asp:ScriptReference Path="~/Scripts/menubar.js" />
                </Scripts>
            </asp:ScriptManager>

The first error is this:

The control with ID '' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.

It happens when I don't have ScriptManager on my page and use ScriptManagerProxy instead.Even though I have ScriptManager on my Master page.

Now when I put a ScriptManager on my page I get a different error.

Only one instance of a ScriptManager can be added to the page.

What do I need to do to get this to work? Is this an issue with one of my Nuget Packages? (JuiceUI,Widgmo, etc)

I would be glad to post code if requested.

EDIT: Yeah, this whole thing has been weird. Oddly the master page did not have issues itself. But only when the other pages used it did I have any problems. Moving it to the first element after the form tag was the solution I believe. Though I had also moved the ScriptManagerProxy up a bit in my code too.

Foi útil?

Solução

The ScriptManager must appear before any ContentPlaceHolders. Generally as Joshua pointed out, the script manager is put at the first element after the form tag. Like so:

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

    <asp:ScriptManager ID="ScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Path="~/Scripts/jquery.js" />
            <asp:ScriptReference Path="~/Scripts/jqueryui.js" />
            <asp:ScriptReference Path="~/Scripts/menubar.js" />
        </Scripts>
    </asp:ScriptManager>

    <div id="container">

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


        </asp:ContentPlaceHolder>
    </div>
</form>

The reason for this is because the .aspx pages that uses this master page provide content that is placed into the ContentPlaceHolder controls. Because your ContentPlaceHolder appeared before your ScriptManager, the ScriptManagerProxy located in your content page was throwing because the ScriptManager would not be defined until later down the page.

This can be a bit odd to think about because you are defining controls in multiple different places. But the codebehind does not execute until everything is put together.

Outras dicas

Put the ScriptManager on masterpage and ScriptManagerProxy on the .aspx page.

you need to put the script manager near your form declaration in Master page;

have a look on this Also: Walkthrough: Creating an Ajax-Enabled Web Site

<body>
    <form runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        ...
    </form>
</body>

For Your Second Question:ScriptManager Control Overview

Only one instance of the ScriptManager control can be added to the page.
The page can include the control directly, or indirectly inside a nested
component such as a user control, content page for a master page, or nested
 master page. If a page already contains a ScriptManager control, but a nested
or parent component needs additional features of the ScriptManager control, the
component can include a   ScriptManagerProxy control.
For example, the ScriptManagerProxy control enables you to add scripts and 
services that are specific to nested components.

you either have to remove your script manager from master page if wanted to use in Content page or Use proxy in content page with in-addition of script manager in master page

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top