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 に答える