2

誰かがこれを理解するのを手伝ってくれることを願っています。私はあちこちを見回しましたが、私を助ける例をまだ見つけていません。私はこれに非常に近いと感じています...

各行の最後にリンクボタンがある asp:gridview があります。onrowcommand を実行する前に、確認ダイアログを表示する必要があります。これが私がしなければならないコードです...何が欠けていますか?

function confirmProcessing(event) {
    event.preventDefault();

    $("#dialog")
        .dialog({
            title: "Confirm Transaction",
            buttons: {
                "Process": function () {                                        
                    $("#dialog").dialog('close');

                },
                Cancel: function() {
                    $("#dialog").dialog('close');
                    return false;
                }
            },
            close: function() {                            
                return false;
            },
            modal: true,
            appendTo: "form"

        })
        .parent()
        .css('z-index', '1005');

}

aspx コード

<div class="row">
    <asp:GridView runat="server" ID="ccList" CssClass="table table-striped table-responsive" ShowHeader="True" AutoGenerateColumns="False" OnRowDataBound="ccList_OnRowDataBound" OnRowCommand="ccList_OnRowCommand">
        <Columns>
            <asp:BoundField DataField="Street" ItemStyle-CssClass="Street" HeaderText="Street"/>
            <asp:BoundField DataField="ZipCode" ItemStyle-CssClass="ZipCode" HeaderText="Zip"/>
            <asp:BoundField DataField="MB4P" ItemStyle-CssClass="MB4P" HeaderText="MB4P"/>
            <asp:BoundField DataField="MB4S" ItemStyle-CssClass="MB4S" HeaderText="MB4S"/>
            <asp:BoundField DataField="BAL" ItemStyle-CssClass="BAL" HeaderText="BAL"/>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:LinkButton runat="server" ID="btnProcess" OnClientClick="confirmProcessing(event);" Text="Process Payment" CommandName="Process" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"/>    
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
</div>

<div id="dialog" style="display:none">        
    <b>Are you sure you want to process this record?</b>
</div>

OnRowCommand コード

protected void ccList_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Process")
    {
        //Do the processing stuff here after confirm dialog.
    }        
}

preventDefault を削除すると、期待される OnRowCommand が起動します。モーダル ダイアログの [プロセス] ボタンを取得してコマンドを起動する方法がわかりません...ここで何が欠けていますか?

前もって感謝します。

4

1 に答える 1

2

OnClientClickLinkBut​​tonのプロパティはRowDataBound、GridView のイベント ハンドラーでUniqueID、ボタンの を引数として設定できconfirmProcessingます。

protected void ccList_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        LinkButton btnProcess = e.Row.FindControl("btnProcess") as LinkButton;
        btnProcess.OnClientClick = string.Format("return confirmProcessing('{0}');", btnProcess.UniqueID);
        ...
    }
}

Javascript イベント ハンドラーは、次のように変更できます。

function confirmProcessing(btnUniqueID) {
    $("#dialog").dialog({
        title: "Confirm Transaction",
        buttons: {
            "Process": function () {
                $("#dialog").dialog('close');
                __doPostBack(btnUniqueID, '');
            },
            Cancel: function () {
                $("#dialog").dialog('close');
                return false;
            }
        },
        close: function () {
            return false;
        },
        modal: true,
        appendTo: "form"

    }).parent().css('z-index', '1005');

    return false;
}

LinkBut​​ton がクリックされると、ダイアログが表示され、関数はfalse最初のポストバックをキャンセルするために戻ります。その後、 をクリックしてダイアログを閉じた場合、LinkBut​​ton の で が呼び出され、ポストバックが発生しProcessます__doPostBackUniqueID

:属性UniqueIDを使用して、クライアント コードで を取得できると考えましたname。Button コントロールでは機能しますが、LinkBut​​ton では機能しません。OnClientClickそのため、コード ビハインドでプロパティを設定することをお勧めします。

于 2016-07-28T03:35:47.383 に答える