2011-04-09 100 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