ajaxctroltoolkik.ModalPopupextender。 10次​​调用Show()

时间:2015-11-13 09:21:15

标签: ajaxcontroltoolkit modalpopupextender

我有ModalPopupExtender的问题。 我将targetcontrolid设置为隐藏字段,并从后面的代码调用show方法。一切正常,直到我第10次调用show方法。然后它突然停止工作。 “对话”无处可见。页面上的控件不再被禁用。当我单击调用show方法但调用show方法的按钮时,调用后面的代码被调用。

我使用Visual Studio 2010

这是我的aspx页面:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="MessageBoxTest.aspx.cs" Inherits="SeceOfC2.TEST.MessageBoxTest" %>
<%@ Register tagName="MessageBox" tagPrefix="uc" src="~/Dialogs/MessageBox.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:UpdatePanel runat="server">
        <ContentTemplate>
            <asp:Button runat="server" ID="TestButton" Text="Test" OnClick="TestButton_OnClick" />





            <asp:HiddenField runat="server" ID="_Hint"/> <%--Brukt til å vite hvorfor denne dialogen ble kalt.--%>
            <asp:HiddenField runat="server" ID="_Parameters"/> <%--Her lagres parameterdata som en Json string.--%>
            <asp:Button runat="server" ID="_dummy"/>
            <asp:Panel runat="server" ID="MessageBoxPanel">
                <asp:Panel runat="server" ID="MessageBoxBorderPanel" BorderColor="LightGray">
                    <div class="dialogheader">
                        <div style="text-align: center; float: left">
                                <asp:Label runat="server" ID="lbHeader"></asp:Label>
                        </div>
                        <div style="float:right">
                            <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/Icons/Small/navigate_cross.png"  />
                        </div>
                        <div style="clear:both"></div>
                    </div>
                    <div class="dialogbody" style="min-height: 50px">
                        <asp:Label runat="server" ID="lbBody"></asp:Label>
                    </div>
                    <div class="dialogbody" style="text-align: center">
                        <asp:Button runat="server" ID="OKButton" Text="OK" OnClick="OnOkClicked"/>
                    </div>
                </asp:Panel>
            </asp:Panel>
            <ajaxToolkit:ModalPopupExtender runat="server" ID="MessageBoxPopupExtender" TargetControlID="_dummy" PopupControlID="MessageBoxPanel" RepositionMode="RepositionOnWindowResizeAndScroll" PopupDragHandleControlID="MessageBoxBorderPanel" DropShadow="True" />



        </ContentTemplate>
    </asp:UpdatePanel>


</asp:Content>

包含脚本管理器的母版页:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="SeceOfC2.SiteMaster" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
    <title></title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
    <script language="JavaScript1.2" src="/scripts/jquery-1.4.1.js" type="text/javascript" defer="defer"></script>
    <script type="text/javascript">
        window.onresize = function(event) {
            var height = $(window).height();
            var width = $(window).width();

            $.ajax({
                url: "/HttpHandlers/getwindowsize.ashx",
                type: "POST",
                data: {
                    Height: height,
                    Width: width,
                    selectedValue: selectedValue
                },
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(response) {
                    // do stuff
                }

            });
        }

    </script>

</head>
<body>
    <form runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div class="page">
        <div class="header">
            <div class="title">
                <h1>
                    SenseOfC Drill execution prototype
                </h1>
            </div>
            <div class="loginDisplay">
                <asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
                    <AnonymousTemplate>
                        [ <a href="~/Account/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ]
                    </AnonymousTemplate>
                    <LoggedInTemplate>
                        Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
                        [ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
                    </LoggedInTemplate>
                </asp:LoginView>
            </div>
            <div class="clear hideSkiplink">
                <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
                    <Items>
                        <asp:MenuItem NavigateUrl="~/Content/Users/DrillView.aspx" Text="Home"/>
                        <asp:MenuItem NavigateUrl="~/Content/Administrators/TreatmentView.aspx" 
                            Text="Admin" Value="Admin"></asp:MenuItem>
                        <asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
                    </Items>
                </asp:Menu>
            </div>
        </div>
        <div class="main">
            <asp:ContentPlaceHolder ID="MainContent" runat="server"/>
        </div>
        <div class="clear">
        </div>
    </div>
    <div class="footer">

    </div>
    </form>
</body>
</html>

这是我背后的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SeceOfC2.Dialogs;
using SeceOfC2.Tools;

namespace SeceOfC2.TEST
{
    public partial class MessageBoxTest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void TestButton_OnClick(object sender, EventArgs e)
        {
            Show("TEST", "TEST");
        }



        public void Show(string caption, string message, string hint = "", MessageBox.Buttons buttons = MessageBox.Buttons.Ok)
        {
            _Hint.Value = hint;
            _Parameters.Value = JsonHelper.Serialize("");
            lbHeader.Text = caption;
            lbBody.Text = message;
            MessageBoxPopupExtender.Show();
        }


        protected void OnOkClicked(object sender, EventArgs e)
        {


        }
    }
}

如果我将TargetControlID设置为可见控件。 ModalPopupExtender仍然有效,但是没有调用代码behid,显然,这使我无法将任何数据放入对话框中的字段中。

更新 我有一个标准的aspx页面(没有母版页):

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MessageBoxTestNoMaster.aspx.cs" Inherits="SeceOfC2.TEST.MessageBoxTestNoMaster" %>
<%@ Register tagName="MessageBox" tagPrefix="uc" src="~/Dialogs/MessageBox.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Button runat="server" ID="TEST" Text="Test" OnClick="TEST_OnClick"/>

            <uc:MessageBox runat="server" ID="MessageBox" />            
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>

对话框已移至usercontrol:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MessageBox.ascx.cs" Inherits="SeceOfC2.Dialogs.MessageBox" %>
<asp:HiddenField runat="server" ID="_Hint"/> <%--Brukt til å vite hvorfor denne dialogen ble kalt.--%>
<asp:HiddenField runat="server" ID="_Parameters"/> <%--Her lagres parameterdata som en Json string.--%>
<asp:HiddenField runat="server" ID="dummy"/>
<asp:Panel runat="server" ID="MessageBoxPanel">
    <%--<ajaxToolkit:DropShadowExtender ID="DropShadowExtender1" runat="server" TargetControlID="MessageBoxBorderPanel" Opacity="0.1" Radius="10"/>--%>
    <asp:Panel runat="server" ID="MessageBoxBorderPanel" BorderColor="LightGray">
        <div class="dialogheader">
            <div style="text-align: center; float: left">
                    <asp:Label runat="server" ID="lbHeader"></asp:Label>
            </div>
            <div style="float:right">
                <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/Icons/Small/navigate_cross.png" OnClick="OnCloseClicked" />
            </div>
            <div style="clear:both"></div>
        </div>
        <div class="dialogbody" style="min-height: 50px">
            <asp:Label runat="server" ID="lbBody"></asp:Label>
        </div>
        <div class="dialogbody" style="text-align: center">
            <asp:Button runat="server" ID="OKButton" Text="OK" OnClick="OnOkClicked"/>
            <asp:Button runat="server" ID="CancelButton" Text="Avbryt" OnClick="OnCancelClicked"/>
            <asp:Button runat="server" ID="YesButton" Text="Ja" OnClick="OnYesClicked"/>
            <asp:Button runat="server" ID="NoButton" Text="Nei" OnClick="OnNoClicked"/>
        </div>
    </asp:Panel>
</asp:Panel>
<ajaxToolkit:ModalPopupExtender runat="server" ID="MessageBoxPopupExtender" TargetControlID="dummy" PopupControlID="MessageBoxPanel" RepositionMode="RepositionOnWindowResizeAndScroll" PopupDragHandleControlID="MessageBoxBorderPanel" DropShadow="True" />

此时没有引用所使用的css类,所以对话框看起来有点赤裸,但它有效!我可以根据需要多次显示和隐藏对话框。

更新2: 链接到css文件没问题。现在,对话框看起来应该是这样。

Upate 3: 试图将脚本管理器的引用从母版页移动到页面。结果相同。不起作用。

更新4: 删除了对css文件的refrecence。消息框现在可以使用。

更新5: 我不是在那里放弃,而是比几分钟前更长一点。

问题似乎与标准asp有关。您从Visual Studio 2010开箱即用的Web应用程序以及您在样式目录中找到的CSS文件。我会尝试用它来调整一下,也许我可以弄清楚什么是ModalPopupExtender的chrasning。

After deactivating some more of the classes in the css files

消息框突然放在表单中的其他内容后面,不再是模态。我可以点击我想要的表格的任何部分和事件。

更新6: 我在没有母版页的情况下重现了错误,只有一个单一的样式元素:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MessageBoxTestNoMaster.aspx.cs" Inherits="SeceOfC2.TEST.MessageBoxTestNoMaster" %>
<%@ Register tagName="MessageBox" tagPrefix="uc" src="~/Dialogs/MessageBox.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
            <style type="text/css">
    .page
    {
        width: 960px;
        background-color: #fff;
        margin: 20px 0px;
        border: 1px solid #496077;
    }
</style>

</head>

<body>

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


    <div class="page">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Button runat="server" ID="TEST" Text="Test" OnClick="TEST_OnClick"/>

            <uc:MessageBox runat="server" ID="MessageBox" />            
        </ContentTemplate>
    </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>

This is what it looks like without master page and only one style element

该对话框可见但隐藏在带有“page”类的div后面。 Hapens经过10次调用后显示方法。模态功能不再处于活动状态,我可以单击对话框中的“确定”按钮和调用show方法的表单中的按钮。

1 个答案:

答案 0 :(得分:1)

我遇到了与AjaxControlToolkit 15.4.1 ModalPopupExtender相同的问题,为我解决的问题是(1)确保所有按钮都在PostBackTrigger标签中,即:

</ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="btnDownload" />
    </Triggers>
</asp:UpdatePanel>

...然后还(2)删除&#34; CancelButtonID&#34;属性如果存在并使用实际按钮单击或命令事件来隐藏扩展器。

我希望我能说出为什么会这样有效,但我对控制工具包的了解不够......希望有所帮助!