jquery 对话框在 asp.net 按钮上关闭

标签 jquery asp.net button dialog onclick

我有一个名为 A 的 aspx 页面,它正在使用母版页。页面 A 有一个链接按钮,在链接按钮上单击我想打开一个 jquery 对话框,加载名为 B 的 aspx。这对我来说效果很好。我有一个asp.net取消按钮在此处输入代码在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>

最佳答案

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

显示对话框的页面...

<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所以我不确定是否有额外的功能可供我使用。

关于jquery 对话框在 asp.net 按钮上关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11866234/

相关文章:

asp.net - Web 服务调用 (asmx) 重定向到 default.aspx

java - Android Studio : Can't switch to new activity

android - 显示某个TextView时如何使按钮消失?

javascript - 动态添加事件目标javascript

具有矩形方向流的jquery图像 slider

javascript - 如何根据事件 anchor 自动将类添加到链接?

javascript - 仅连接并打印带有文本的值,并在之间添加逗号

c# - ASP.NET : How to deny a page to be accesed by users and set permissions?

asp.net - 动态修改web.config文件有什么问题吗

C# 按钮不触发?