简体   繁体   English

用户在jquery对话框中显示后无回发

[英]No postback after user confrim in jquery dialog box

I am newsiest on jQuery. 我在jQuery上是最新的。 I need to show the dialog box to get the user response. 我需要显示对话框以获取用户响应。 If the use click confirm, I need to update the database on sever. 如果使用单击确认,则需要在服务器上更新数据库。 I found the example jQuery dialog Confirm-JSFiddle and followed the code. 我找到了示例jQuery对话框Confirm-JSFiddle并遵循了代码。 However, after the user click confirm, it is not postback to server. 但是,用户单击确认后,它不会回发到服务器。 Would someone tell me how to fix it. 有人会告诉我如何解决它。

There is my jQuery script code: 有我的jQuery脚本代码:

           $(document).ready(function() {
               $("#dialog-confirm").dialog({
                   autoOpen: false,
                   modal: true
               });
           });

           $(function() {

               $("#dialog-confirm").dialog({
                   autoOpen: false,
                   modal: true,
                   buttons : {
                       "Confirm" : function() {
                           $(this).dialog("close");
                           return true;        
                       },
                       "Cancel" : function() {
                           $(this).dialog("close");
                           return false;
                       }
                   }
               });

               $("#Button1").on("click", function(e) {
                   e.preventDefault();
                   $("#dialog-confirm").dialog("open");
               });

           });

There is the code on vb.net vb.net上有代码

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim i As Integer = 0
End Sub

There is the button on aspx page 在aspx页面上有按钮

  <asp:button id="Button1" runat="server"  text="test" visible="true" />

You're just need one step to do postback by using appendTo function to bind with target form: 您只需要执行一步操作即可,方法是使用appendTo函数与目标表单绑定:

$("#Button1").on("click", function(e) {
    e.preventDefault();
    $("#dialog-confirm").dialog("open");  
    $("#dialog-confirm").parent().appendTo($("form:first"));
});

<asp:Button id="Button1" runat="server"  text="test" visible="true" OnClick="Button1_Click" />

Of course, if you're using dynamic client ID (without ClientIDMode="Static" attribute at asp:Button ), you need to use ClientID instead of button's server ID: 当然,如果您使用的是动态客户端ID(在asp:Button处没有ClientIDMode="Static"属性),则需要使用ClientID而不是button的服务器ID:

$("#<%= Button1.ClientID %>").on("click", function(e) {
    e.preventDefault();
    $("#dialog-confirm").dialog("open");
    $("#dialog-confirm").parent().appendTo($("form:first"));
});

Or you can embed appendTo into dialog setting (with jQuery 1.10 and above): 或者,您可以将appendTo嵌入dialog设置(使用jQuery 1.10及更高版本):

$("#dialog-confirm").dialog({
    autoOpen: false,
    modal: true,
    buttons : {
        "Confirm" : function() {
            $(this).dialog("close");
            return true;        
        },
        "Cancel" : function() {
            $(this).dialog("close");
            return false;
        }
    },
    appendTo: "form" // append this setting
});

If appendTo doesn't work with your page, try __doPostBack method (but not guaranteed to work with all browsers): 如果appendTo不适用于您的页面,请尝试__doPostBack方法(但不能保证与所有浏览器一起使用):

__doPostBack('<%= Button1.UniqueID %>', '');

Similar issues: 类似问题:

jQuery UI Dialog with ASP.NET button postback 带ASP.NET按钮回发的jQuery UI对话框

jQuery modal form dialog postback problems jQuery模态表单对话框回发问题

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

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