【问题标题】:I am not able open dialog box on clicking a button here is the code我无法在单击按钮时打开对话框这里是代码
【发布时间】:2013-03-07 05:59:59
【问题描述】:

asp.net 代码

 <asp:Button ID="btnnext" runat="server" Text="Update" onclick="btnnext_Click"  />

<div id= "DisplayEnteredDetails" >

<asp:GridView ID="grdDisplayEnteredDetails" runat="server"   >
                    </asp:GridView> 
</div>

调用函数

  <script type="Text/javascript">
    $(function () {
     $('#DisplayEnteredDetails').dialog({
                autoOpen: false,
                width: 600,
                height: 500,
                hide: 'Transfer',
                open: function (type, data) {
                    $(this).parent().appendTo("form");
                }
            });
     // Dialog button
            $('#ctl00_Main_btnnext').click(function () {
                $('#DisplayEnteredDetails').dialog('open');
                return false;
            });


        });   
    </script>

我在母版页中给出了链接

<link rel="stylesheet" type="text/css" href="~/styles/StyleSheet.css" />
    <link href="jquery/css/jquery.ui.all.css" rel="stylesheet" type="text/css" />

相同的代码在其他项目中有效,但在我的应用程序中无效

【问题讨论】:

  • 显示什么错误?
  • 不显示任何错误
  • 控制台中的任何内容?脚本错误?
  • 在母版页参考中添加 jquery 库和 ui
  • @ShodhanHuli : 你只包含 css,不包含 js

标签: jquery asp.net dialog


【解决方案1】:

&lt;script type="Text/javascript"&gt; 替换为&lt;script&gt; 并检查。脚本标签应全部为小写字母。所以,&lt;script type="text/javascript"&gt; 或简单的&lt;script&gt; 应该可以工作。

否则您可能忘记在 html 中添加 jquery Ui 引用。 (假设,因为它在您提供的代码中不可见)

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script> 
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>

【讨论】:

  • @ShodhanHuli 你在哪里添加 js 文件?请也发布该代码。
  • 这是我在母版页中给出的唯一参考其他项目中的参考作品
  • @ShodhanHuli 即css 文件。您还需要添加 jquery 和 jquery UI 引用。
  • C:\Users\Vantage Agore\Documents\Visual Studio 2010\Projects\odonovaTest\jquery 我只是将粘贴的 j 查询文件夹复制到我的应用程序中,我没有提供任何其他参考
  • @ShodhanHuli &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" &gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"&gt;&lt;/script&gt; 在 html 中的 link 标记上方添加这一行。
【解决方案2】:

要使用 jQuery 显示对话框,您需要做两件事:

  1. Download jQuery
  2. Download jQuery UI

将这两个文件放在您的项目中,并在页面/母版页上添加对它们的引用:

<script src="Scripts/jquery-1.9.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui.js" type="text/javascript"></script>

这里有一个完整的例子:

P.S:记得把脚本中按钮的id改成正确的值

<head runat="server">
    <title>Dialog</title>
    <script src="Scripts/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $('#DisplayEnteredDetails').dialog({
                autoOpen: false,
                width: 600,
                height: 500,
                hide: 'Transfer',
                open: function (type, data) {
                    $(this).parent().appendTo("form");
                }
            });
            // Dialog button
            $('#ctl00_Main_btnnext').click(function () {
                $('#DisplayEnteredDetails').dialog('open');
                return false;
            });
        });  
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Button ID="ctl00_Main_btnnext" runat="server" Text="Update" OnClick="btnnext_Click" />
    <div id="DisplayEnteredDetails" style="border:1px solid #2d2d2d;">
        <asp:GridView ID="grdDisplayEnteredDetails" runat="server">
        </asp:GridView>
    </div>
    </form>
</body>

【讨论】:

    猜你喜欢
    • 2011-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2011-06-07
    • 1970-01-01
    相关资源
    最近更新 更多