Ajax控件工具包ModalPopupExtender在Visual Studio 2012中无法工作

4
我之前在Nuget中使用Ajax Control Toolkit版本7.1213与Visual Studio一起使用。但是当我尝试使用ModalPopupExtender时,它根本不起作用。我浏览了Stackoverflow、Codeproject以及其他知名网站,但他们的建议都对我的代码无济于事。
我还发现很多使用最新AjaxControlToolkit和Visual Studio 2012的用户都遇到了同样的问题。
这是主页面。
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="Attendance1.Site1" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %> 
<!DOCTYPE html>

<html lang="en">
<head id="Head1" runat="server">
    <meta charset="utf-8" />
    <title><%: Page.Title %> - My ASP.NET Application</title>
    <asp:PlaceHolder ID="PlaceHolder1" runat="server">     
          <%: Scripts.Render("~/bundles/modernizr") %>
    </asp:PlaceHolder>  
    <webopt:BundleReference ID="BundleReference1" runat="server" Path="~/Content/css" /> 
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <meta name="viewport" content="width=device-width" />
    <asp:ContentPlaceHolder runat="server" ID="HeadContent" />
</head>
<body>
    <form id="Form1" runat="server">

    <header>
        <div class="content-wrapper">
            <div class="float-left">
                <p class="site-title">
                    <img src="Images/logo.png"  />
                </p>
            </div>
            <div class="float-right">
                <section id="login">
                    <asp:LoginView ID="LoginView1" runat="server" ViewStateMode="Disabled">
                        <AnonymousTemplate>
                            <ul>


                            </ul>
                        </AnonymousTemplate>
                        <LoggedInTemplate>
                            <p>
                                Hello, <a id="A1" runat="server" class="username" href="~/Account/Manage" title="Manage your account">
                                    <asp:LoginName ID="LoginName1" runat="server" CssClass="username" /></a>!
                                <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="Redirect" LogoutText="Log off" LogoutPageUrl="~/" />
                            </p>
                        </LoggedInTemplate>
                    </asp:LoginView>
                </section>
                <nav>
                    <ul id="menu">


                    </ul>
                </nav>
            </div>
        </div>
    </header>
    <div id="body">
        <asp:ContentPlaceHolder runat="server" ID="FeaturedContent" />
        <section class="content-wrapper main-content clear-fix">

            <asp:ScriptManager ID="ScriptManager1" runat="server">
        <Scripts>

            <%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=272931&clcid=0x409 --%>
            <%--Framework Scripts--%>

           <asp:ScriptReference Name="MsAjaxBundle" />
            <asp:ScriptReference Name="jquery" />
            <asp:ScriptReference Name="jquery.ui.combined" />
            <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
            <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
            <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
            <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
            <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
            <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
            <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
            <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
            <asp:ScriptReference Name="WebFormsBundle" />
            <%--Site Scripts--%>

        </Scripts>
    </asp:ScriptManager>
            <asp:ContentPlaceHolder runat="server" ID="MainContent" />
        </section>
    </div>
    <footer>
        <div class="content-wrapper">
            <div class="float-left">
                <p>&copy; <%: DateTime.Now.Year %> - My ASP.NET Application</p>
            </div>
        </div>
    </footer>
    </form>
</body>
</html>

这是我的内容页面。

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site1.Master" CodeBehind="Login.aspx.cs" Inherits="abc" %>

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

            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                <asp:panel ID="Panel1" style="display:none" runat ="server">
                <div class="HelloWorldPopup">
                    <div class="PopupHeader" id="PopupHeader">Header</div>
                    <div class="PopupBody">
                        <p>This is sample modal dialog</p>
                    </div>
                    <div class="Controls">
                        <input id ="btnOk" type="button" value="Done" />
                        <input id="btnCancel" type="button" value="Cancel" />
                    </div>
                </div>
            </asp:panel>
                    <asp:Button ID="Button1" runat="server" Text="Click here to show the modal" />
                    <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" DynamicServicePath="" PopupControlID="Panel1" Enabled="True" CancelControlID="btnCancel" TargetControlID="Button1">
                    </ajaxToolkit:ModalPopupExtender>
        </ContentTemplate>
    </asp:UpdatePanel>

</asp:Content>

感谢您的提前帮助。
1个回答

4

您需要更改以下行:

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

使用这个:

<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnableScriptGlobalization="true">

非常感谢!我已经试图找出为什么它没有工作了大约两个小时! - yrazlik
在现代版本的Ajax工具包中,他们实际上摆脱了ToolkitScriptManager。我曾经遇到过同样的问题,但愚蠢的是我从未检查过控制台。结果发现我缺少Scripts\WebForms\MsAjax,这些文件会在新项目中自动创建。 - Clay Smith

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接