2011-04-09 98 views
1

Iam嘗試在jQuery模式對話框中打開一個彈出登錄窗體,單擊一個asp.net頁面上的按鈕。但模態對話框並不是彈出窗口。請告訴Iam做錯了什麼。asp.Net jquery模態對話框表

這裏是我的HTML代碼:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ModalForm.aspx.cs" Inherits="ModalForm" %> 

<!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> 
    <script src="js/jquery.js" type="text/javascript"></script> 
    <link href="css/jquery.modaldialog.css" rel="stylesheet" type="text/css" /> 
    <script src="js/jquery.modaldialog.js" type="text/javascript"></script> 
    <script type="text/javascript"> 
     $(document).ready(function() { 
      $("#dialog").dialog({ 
       bgiframe: true, 
       autoOpen: false, 
       height: 300, 
       modal: true, 
       buttons: { 
        Cancel: function() { 
        $(this).dialog("close"); 
       } 
       }, 
       close: function() { 
       allFields.val("").removeClass("ui-state-error"); 
       } 
      }); 

      // Display the modal dialog. 
      $("#btndialog").click(function() { 

       $("#dialog").dialog("open"); 
      }); 

     }); 

    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
     <div id="dialog" title="Please Login"> 
      <asp:Login ID="LoginForm" runat="server" /> 
     </div> 
     <asp:Button ID="btndialog" runat="server" Text="Click" />   
    </form> 
</body> 
</html> 

感謝

+0

是模型對話框完全不顯示或者說,它不顯示爲模型窗口的問題,但作爲內聯內容? – Tnem 2011-04-09 12:51:31

回答

0

的JavaScript代碼看起來是正確的。

檢查瀏覽器是否找到.js文件。

否則,ASP.NET改變元素的ID,請嘗試使用ClientID屬性:

$(document).ready(function() { 
     $("#<%= dialog.ClientID %>").dialog({ 
      bgiframe: true, 
      autoOpen: false, 
      height: 300, 
      modal: true, 
      buttons: { 
       Cancel: function() { 
       $(this).dialog("close"); 
      } 
      }, 
      close: function() { 
      allFields.val("").removeClass("ui-state-error"); 
      } 
     }); 

     // Display the modal dialog. 
     $("#<%= btndialog.ClientID %>").click(function() { 

      $("#<%= dialog.ClientID %>").dialog("open"); 
     }); 

    }); 
+0

嗨,那裏,js文件出現在瀏覽器中。此外,當我註釋掉javascript中的所有內容並僅保留$(「#<%= btndialog.ClientID%>」)時,單擊(function(){ alert('helo'); });警報出現在屏幕上。所以它看起來像jQuery不能顯示模式對話框。 – user699940 2011-04-09 13:07:40

+0

我只在*** jsFiddle ***上測試過你的html,它正在工作。你可以在這裏檢查它:http://jsfiddle.net/8dbwh/。你正在使用哪個版本的jquery/ui?您可以訪問http://jqueryui.com/download並構建一個適合您需求的自定義'.js/.css'文件。 – manji 2011-04-09 13:23:55

+0

您好,非常感謝您的幫助。我在jsfiddle上發現它使用的是jQuery 1.8.9 UI。我在我的代碼中改變了jquery版本,它工作。非常感謝。 :) – user699940 2011-04-09 16:14:46