c# - 使用 ASP.NET 按钮显示的 jQuery UI 对话框

标签 c# asp.net jquery-ui dialog

我试图在用户单击 ASP.Net 按钮时显示模式对话框。这是我的页面:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <script src="js/jquery-1.2.6.min.js" type="text/javascript"></script>
    <script src="js/jquery-ui-1.6.custom.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function() {

            $("#dialog").dialog({
                bgiframe: true,
                autoOpen: false,
                height: 300,
                modal: true,
                buttons: {
                    'Ok': function() {
                        $(this).dialog('close');
                    },
                    Cancel: function() {
                        $(this).dialog('close');
                    }
                },
                close: function() {
                    ;
                }
            });
        });
        function ShowDialog() {
            $('#dialog').dialog('open');
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="TreeNew" runat="server" Text="New" OnClientClick="ShowDialog();"/>
        <asp:Label ID="Message" runat="server"></asp:Label>
        <div id="dialog" title="Select content type">
            <p id="validateTips">All form fields are required.</p>
            <asp:RadioButtonList ID="ContentTypeList" runat="server">
                <asp:ListItem Value="1">Text</asp:ListItem>
                <asp:ListItem Value="2">Image</asp:ListItem>
                <asp:ListItem Value="3">Audio</asp:ListItem>
                <asp:ListItem Value="4">Video</asp:ListItem>
        </asp:RadioButtonList>
        </div>
    </div>
    </form>
</body>
</html>

当我点击 TreeNew 按钮时出现模态弹出窗口,但页面立即执行回发。

发生了什么事?

最佳答案

同时添加 return false;将解决您的问题(如其他答案所建议的那样),我认为您最好的办法是使用标准的 HTML 按钮。在这种情况下没有理由使用 ASP.NET 控件,因为您不打算回发。

但是,如果您坚持使用 ASP.NET 按钮,至少设置 UseSubmitBehavior="False"这样按钮就会呈现为 <input type="button"/>而不是 <input type="submit"/> .

关于c# - 使用 ASP.NET 按钮显示的 jQuery UI 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2321156/

相关文章:

Jquery on drop 删除助手

c# - 匿名用户授权(自动认证)

ASP.NET WebAPI Identity 2 - 用户注册/注册方法上的 GetOwinContext 错误

asp.net - 数据直接绑定(bind)到商店查询

jQuery UI 可排序 : is it possible to restrict possible positions of individual elements?

javascript - 使用 .slideUp 的函数没有动画

c# - visual studio中的 "File has no header"构建警告是什么意思

c# - 表示层控制修改

c# - 如何像 HttpWebRequest 一样使用 TcpClient 执行 HTTPS?

c# - ASP Webforms 验证控件不工作