【问题标题】:jquery dialog close on asp.net button clickjquery对话框关闭asp.net按钮单击
【发布时间】:2012-08-08 14:04:47
【问题描述】:

我有一个名为 A 的 aspx 页面,它正在使用母版页。页面A有一个链接按钮,点击链接按钮我想打开一个加载名为B的aspx的jquery对话框。这对我来说很好。我有一个 asp.net 取消按钮 oenter code heren 页面 B,在取消按钮上单击我想关闭 jquery 对话框并留在页面 A。在我的代码中,jquery 对话框正在关闭,但它重新加载页面 B浏览器。

母版页

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="jQueryTest.Site1" %>

<!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>Untitled Page</title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>

    <script src="../javascript/jquery-1.7.2.min.js" type="text/javascript"></script>

    <script src="../javascript/jquery-ui-1.8.22.custom.min.js" type="text/javascript"></script>

    <link href="/css/ui-lightness/jquery-ui-1.8.22.custom.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">
    $(document).ready(function () {
        var mydiv = $("#dialog").dialog({   
            autoOpen: false,
            resizable: false,
            height: 700,
            width: 900,
            modal: true            
        });        
        mydiv.parent().appendTo(jQuery("form")); 


        });

        function showPanel(){
        var mydiv = $("#dialog")
        // Load the content using AJAX
        mydiv.load('/WebForm1.aspx');
        // Open the dialog        
        mydiv.dialog('open');

        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

default.aspx(A 页)

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

<asp:Content ID="contect1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div>
        <asp:LinkButton ID="lnkChangePwd" Text="Click" OnClientClick="showPanel();return false;"
            runat="server"></asp:LinkButton>
    </div>
    <div id="dialog" style="width: 60%; height: 45%" title="Change password">
    </div>   

</asp:Content>

webform1.aspx(B页)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="jQueryTest.WebForm1" %>

<!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>Untitled Page</title>

    <script src="../javascript/jquery-1.7.2.min.js" type="text/javascript"></script>

    <script src="../javascript/jquery-ui-1.8.22.custom.min.js" type="text/javascript"></script>

    <link href="/css/ui-lightness/jquery-ui-1.8.22.custom.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">



    $(document).ready($(function () {
     $("#<%=Button1.ClientID %>").bind("click", function (event) {
    $("#dialog").dialog("close");    

});

}));

    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        this is webform 1
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>

【问题讨论】:

    标签: jquery asp.net button dialog onclick


    【解决方案1】:

    这样的事情对我有用...

    显示对话框的页面...

    <html>
    <head>
        ...link js files here...
    </head>
    <body>
        <div id="deleteDialog"></div>
    </body>
    </html>
    

    作为对话框内容的页面...

    <html>
    <head>
        ...link js files here...
    </head>
    <body>
        <input type="submit" value="Close" id="uxCloseDialog" />
    </body>
    </html>
    

    jquery 显示和关闭对话框...

    var deleteDialog;
    
    deleteDialog = $("#deleteDialog").dialog({
        autoOpen: false,
        resizable: false,
        width: "auto",
        modal: true
    });
    
    $(".button-delete-24").click(function () {
        var id = $(this).attr('data-id');
        deleteDialog.empty();
        deleteDialog.load("/myDialogPage.aspx"
            , function () {
                $("#uxCloseDialog").click(function () {
                    deleteDialog.dialog("close");
                    return false;
                });
            });
        deleteDialog.dialog("open");
        return false;
    });
    

    我确实使用jQuery UI,所以我不确定是否有额外的功能可供我使用。

    【讨论】:

    • 对话框已关闭,但仍会重新加载同一页面。
    【解决方案2】:

    尝试使用 window.parent:

    window.parent.jQuery("#dialog").dialog('close');
    

    【讨论】:

    • 对话框已关闭,但仍会重新加载同一页面。
    猜你喜欢
    • 2013-04-06
    • 1970-01-01
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多