1

我在 aspx 代码中有以下方法,它后面显示一个 jquery 对话框。如果用户单击对话框上的“提交” ,此方法是否有可能返回true ?

    Sub DisplayDialog()
        Dim title As String = "title"
        Dim content As New StringBuilder()
        content.Append(@"<script type=text/javascript>
          $(function () {
           $('#dialog')
            .dialog({
            title: 'title',
            modal: 'true',
            buttons: {
                'Submit': function () { 
                },
                'Cancel': function () {
                    $(this)
                        .dialog('close');
                }
            }
        });
    });
</script>")
     ClientScript.RegisterStartupScript(Me.[GetType](), title, content.ToString())
    End Sub

编辑:

这是我所拥有的更完整的图片:

Sub GridView1_onRowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
    Select Case e.CommandName
        Case "Upload"
            DisplayDialog()
            //Get result here from jquery dialog. Do something if result was true             
        Case "Something"
     End Select
End Sub
4

1 回答 1

1

如果你想使用模态对话框的返回来执行一个动作,这是你应该遵循的模式:

<script type="text/javascript">
    $(function () {
        var $dialog = $("#dialog");
        var $foo = $("input:submit[id$=foo]");
        var confirmed = false;

        $dialog.hide();

        $dialog.dialog({
            width: "300px",
            modal: true,
            autoOpen: false,
            buttons: {
                OK: function (e) {
                    $dialog.dialog("close");
                    confirmed = true;
                    $foo.click();
                },
                Cancel: function (e) {
                    $dialog.dialog("close");
                    confirmed = false;
                }
            }
        });

        $foo.click(function (e) {
            if (!confirmed) {
                $dialog.dialog("open");
            }

            return confirmed;
        });
    });
</script>

    <div>
        <asp:Button Text="Submit" runat="server" ID="foo" OnClick="foo_Click" />
    </div>
    <div id="dialog">
        <asp:Label Text="Are u sure u wanna do it?" runat="server" />
    </div>

基本上,您使用标志来指示按下了哪个按钮,并在单击按钮时返回该标志。

您可以获取此示例并对其进行调整以适合您的特定需求

这是我的 GitHub 上的完整工作示例

于 2012-09-27T18:43:49.697 回答