AJAX ModalPopup无法显示

时间:2013-12-17 20:20:03

标签: javascript ajax

我似乎无法显示Modal弹出窗口。使用下面的代码,显示屏将失焦,但不显示任何窗口。

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AjaxToolkit" %>

<!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">
    <div>     
        <asp:Button ID="btnShow" runat="server" Text="Open ModalPopup" OnClientClick="return ShowModalPopup('modal');" />    
        <ajaxToolkit:ModalPopupExtender runat="server" ID="modal" BackgroundCssClass="darken" 
                            CancelControlID="btnCancel" PopupControlID="pnl" TargetControlID="btnShow" />
        <asp:Panel ID="pnl" runat="server" style="width:55%;display:none;">
            <h1>You can now see me!</h1>
            <p>"Lorem ipsum dolor sit amet, consectetur adipisicing elit, 
            sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 
            Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris 
            nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in 
            reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla 
            pariatur. Excepteur sint occaecat cupidatat non proident, sunt in 
            culpa qui officia deserunt mollit anim id est laborum."</p>
            <asp:Button ID="btnCancel" runat="server" Text="Close" />
      </asp:Panel>
      <asp:ScriptManager ID="ScriptManager1" runat="server"/>


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



<script type="text/javascript">
    function ShowModalPop(PopupExtenderID) {
        var ModalPopWindowShow = $find(PopupExtenderID);

        if (ModalPopWindowShow) {
            ModalPopWindowShow.show();
        }

        return false;
    }
</script>

代码背后:

protected void Page_Load(object sender, EventArgs e)
        {
            _grid.DataSource = BuildList();
            _grid.DataBind();
        }

        private List<EntityPerson> BuildList()
        {
            ...
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            btnShow.Click +=new EventHandler(btnShow_Click);
        }

        protected void btnShow_Click(object sender, EventArgs e)
        {
            Button btnShow = sender as Button;
            ScriptManager.RegisterStartupScript(btnShow, btnShow.GetType(), "Popup", "return ShowModalPopup('modal');", true);
        }

感谢您的所有帮助。 如果有另一种方式来显示一个带有AJAX的弹出窗口,我也很感激这方面的指导。 当用户点击网格中的单元格时,我只需要能够在模态窗口中显示单元格内容。

1 个答案:

答案 0 :(得分:0)

我替换了

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

<ajaxToolkit:ToolkitScriptManager ID="ajaxSM" runat="server" />

我得到了弹出窗口。