在转发器中的asp.net按钮上的Jquery确认对话框

时间:2013-04-17 08:09:15

标签: jquery asp.net dialog repeater confirmation

我想在asp.net按钮点击进行jquery确认,这是在转发器内,但下面的代码不起作用。

它甚至没有进入函数Confirmation()

当页面加载时,confirmDialog div可见,因为它是一个常规div元素而不是弹出这不再是问题但是其余部分保持不变

我错过了什么?

<asp:Content ID="Content2" ContentPlaceHolderID="AdminHead" runat="server">
   <script lang="javascript" type="text/javascript">
       $(function () {
           $("#confirmDialog").dialog({
               autoOpen: false,
               modal: true,
               buttons: {
                   'Confirm': function () {
                       $(this).dialog('close');
                       return true;
                   },
                   'Cancel': function () {
                       $(this).dialog('close');
                       return false;
                    }
                }
            });
            function Confirmation() { 
            alert("IN");

                $('#confirmDialog')
            .dialog('option', 'onOk', $(this).attr('href'))
            .dialog('open');
            }
        });
    </script>
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="AdminContentPlaceHolder" runat="server">

<div id="confirmDialog">
    <p>ARE YOU SURE YOU WANT TO CONFIRM THIS ACTION?</p>
</div>
<asp:Repeater ID="Repeater1" runat="server">
   <HeaderTemplate>
        <div class="repeaterItem">
            <table id="AdminTable">
              .
              .
              .
    </HeaderTemplate>
    <ItemTemplate>
              .
              .
              .
              <asp:Button ID="DeleteButton" CssClass="delete" OnClick="ClickDelete" OnClientClick="Confirmation();return false;" runat="server"
                    Text="DELETE" CommandArgument="<%#(Container.DataItem as TagObject).ID %>" ClientIDMode="AutoID" />
            </th>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
              .
              .
              .
        </table></div>
    </FooterTemplate>
</asp:Repeater>
</asp:Content>

------------------------------------- ISSUE-解决------- -----------------------

我的最终守则:

    <asp:Content ID="Content2" ContentPlaceHolderID="AdminHead" runat="server">
   <script lang="javascript" type="text/javascript">
    var deleteButton;
    $(function () {
        $("#confirmDialog").dialog({
            autoOpen: false,
            modal: true,
            buttons: {
                'Confirm': function () {
                    $(this).dialog('close');
                    __doPostBack($(deleteButton).attr('name'), '');
                },
                'Cancel': function () {
                    $(this).dialog('close');
                    callback(false);
                }
            }
        });
    });
    function Confirmation() {
        deleteButton = this;
            $('#confirmDialog').dialog('open');
        }
</script>
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="AdminContentPlaceHolder" runat="server">

<div id="confirmDialog">
    <p>ARE YOU SURE YOU WANT TO CONFIRM THIS ACTION?</p>
</div>
<asp:Repeater ID="Repeater1" runat="server">
   <HeaderTemplate>
        <div class="repeaterItem">
            <table id="AdminTable">
              .
              .
              .
    </HeaderTemplate>
    <ItemTemplate>
              .
              .
              .
              <asp:Button ID="DeleteButton" CssClass="delete" OnClick="ClickDelete" OnClientClick="Confirmation();" runat="server"
                    Text="DELETE" CommandArgument="<%#(Container.DataItem as TagObject).ID %>" ClientIDMode="AutoID" />
            </th>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
              .
              .
              .
        </table></div>
    </FooterTemplate>
</asp:Repeater>
</asp:Content>

1 个答案:

答案 0 :(得分:1)

首先从块中取出确认功能。编辑让它真正起作用:

<script lang="javascript" type="text/javascript">
    $(function () {
        $("#confirmDialog").dialog({
            autoOpen: false,
            modal: true,
            buttons: {
                'Confirm': function () {
                    $(this).dialog('close');
                    return true;
                },
                'Cancel': function () {
                    $(this).dialog('close');
                    return false;
                }
            }
        });

    });
    function Confirmation() {
        alert("IN");

        $('#confirmDialog').dialog('open');
    }
</script>


<asp:Button ID="DeleteButton" CssClass="delete" OnClick="ClickDelete" OnClientClick="Confirmation();return false;"
    runat="server" Text="DELETE" CommandArgument="asd" ClientIDMode="AutoID" />