简体   繁体   English

jQuery模式弹出对话框按钮不触发?

[英]jquery modal popup dialog button is not firing?

Here ok button is not firing when i include modal:true, 当我包含modal:true时,这里的OK按钮不会触发

Aspx: Aspx:

<script type="text/javascript">
            $(function () {
                $("[id*=Button2]").live("click", function () {
                    $("#dialog").dialog({
                        modal: true,
                        buttons: {
                            Ok: function () {
                                $("#<%=Button3.ClientID %>").click();                           
                            },
                            Close: function () {
                                $(this).dialog('close');
                            }
                        }
                    });
                });
            });

     </script>

<input type="button" id="Button2" value="click here" name="Button2" />

   <asp:Button ID="Button3" runat="server" Text="Button" style="display:none;" OnClick = "Button_Click"/>

    <div id="dialog" style="display:none">
        <asp:Label ID="Label1" runat="server" Text="Enter ur name"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox>

    </div>

I need to call this function when ok button is clicked and this function is not invoked when modal:true, is included in the jquery 我需要在单击ok按钮时调用此函数,并且当jQuery中包含modal:true时不调用此函数

C#:code behind: C#:后面的代码:

 protected void Button_Click(object sender, EventArgs e)
        {
            ClientScript.RegisterStartupScript(Page.GetType(), "key", "alert('Button Clicked')", true);

        }

May be you need something like this. 可能您需要这样的东西。

If you can not post back why not use ajax 如果您不能发回邮件,为什么不使用ajax

<!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>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <link rel="stylesheet" href="/resources/demos/style.css">
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script>
        $(function () {
            $('#btnModal').on('click', function (e) {
                e.preventDefault();
                $("#dialog").dialog({
                    modal: true,
                    buttons: {
                        Ok: function () {
                            // alert('Hi');
                            //  document.getElementById('btnModal').click();
                            var data = {}
                            data.x = "1";
                            $.ajax({
                                type: "POST",
                                url: "Dialog.aspx/GeTestJsons",
                                data: JSON.stringify(data),
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success: function (result) {
                                    //alert(result.d);//data from backend
                                    $('#dialog').dialog('close');
                                }
                            });


                        },
                        Close: function () {
                            $(this).dialog('close');
                        }
                    }
                });
            });

        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>
            <asp:Button ID="btnModal" runat="server" ClientIDMode="Static" Text="Click me"  />
        </div>


        <div id="dialog" title="Basic dialog" style="display: none">
            <p>
                This is the default dialog which is useful for displaying information. The dialog
                window can be moved, resized and closed with the 'x' icon.</p>
        </div>
    </div>
    </form>
</body>
</html> 

and .cs 和.cs

[WebMethod]
    public static String GeTestJsons(String x)
    {

        return "hi";
    } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM