2012-08-08 32 views
2

我有一個aspx頁面,它使用了一個母版頁。頁面A有一個鏈接按鈕,點擊鏈接按鈕,我想打開一個jQuery對話框加載aspx,名爲B.這對我來說很好。我有一個asp.net取消按鈕0 enter code here在頁面B上取消按鈕單擊我想要關閉jquery對話框並保留在頁面A.在我的代碼中,jquery對話框正在關閉,但它重新加載瀏覽器中的頁面B.關於asp.net按鈕的jquery對話框點擊

母版頁

<%@ 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的(第一個)

<%@ 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> 

回答

2

像這樣的東西很適合我.. 。

顯示頁面對話框......

<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所以我不確定是否有額外的功能提供給我或沒有。使用window.parent

+0

對話框被關閉,但它仍然重新加載相同的頁面。 – Vijay 2012-08-09 06:45:53

0

嘗試:

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

對話框關閉,但它仍然重新加載相同的頁面。 – Vijay 2012-08-09 06:31:47

相關問題