简体   繁体   English

jQuery确认对话框在aspx中消失

[英]Jquery Confirm Dialog box disappears in aspx

I am using custom jquery confirm dialog box on button click in aspx page. 我正在使用自定义jQuery确认对话框单击aspx页面中的按钮。 Problem is that when I am clicking the button the dialog box is coming but automatically closes after some seconds due to autopostback. 问题是,当我单击按钮时,对话框即将出现,但由于自动回发,在几秒钟后会自动关闭。 How to resolve it? 怎么解决呢?

Here is my code...

<script>
    $(function confirmation () {
        $('#btnUpdate').click(function () {
            $('#dialog').dialogBox({
                content:'Are you sure to update..!!',
                hasClose: true,
                effect: 'fade',
                hasBtn: true,
                confirm: function () {
                    $('#message').dialogBox({
                        title: 'Confirmation..',
                        content: 'Updated Sucessfully..!!',
                        hasClose: true
                    })
                }
            })
        })
    })
</script>
<asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click" OnClientClick="return confirmation()" />

Try adding UseSubmitBehavior="false" in <asp:Button> to prevent the button triggering the postback. 尝试在<asp:Button>添加UseSubmitBehavior="false" ,以防止按钮触发回发。

Sample: 样品:

<asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click" OnClientClick="return confirmation()" UseSubmitBehavior="false" />

Add the event parameter to your click handler, and then cancel (prevent) the default action : 将event参数添加到您的点击处理程序中,然后取消(阻止)默认操作

$('#btnUpdate').click(function (e) {
    e.preventDefault();

})

Do the following changes: 进行以下更改:

  • Cancel the default behavior of the asp. 取消asp的默认行为。
  • Replace the #btnUpdate with #<%=btnUpdate.ClientID%> 将#btnUpdate替换为#<%= btnUpdate.ClientID%>
  • Call the postback when the confirm is true. 确认为真时,请调用回发。

Below is the updated code: 下面是更新的代码:

$("#<%=btnUpdate.ClientID%>").click(function(){
    event.preventDefault();
    $('#dialog').dialogBox({
        content:'Are you sure to update..!!',
        hasClose: true,
        effect: 'fade',
        hasBtn: true,
        confirmValue: 'I am sure',
        confirm: function(){
            __doPostBack($('#<%=btnUpdate.ClientID %>').attr('name'), '');
        }
    });
})    

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

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