1

I want to do a jquery confirmation on asp.net button click which is inside repeater but the code below doesnt work.

It doesnt even get in the function Confirmation()

and when the page is loaded confirmDialog div is visible like it's a regular div element not a popup this is no longer issue but rest remains the same

what am I missing?

<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-SOLVED------------------------------

My Final Code:

    <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>
12
  • why have you used return false OnClientClick="Confirmation();return false;" ? Commented Apr 17, 2013 at 8:14
  • Well i have been searching the net for 2 days about this and as i find out return false stops asp.net from doing default action but apparently it doesnt work for me i have tried it without it and it didnt work as well. Commented Apr 17, 2013 at 8:22
  • I guess you were suppose to use it like this OnClientClick=" return Confirmation();" , and in the confirmation function return the true to submit asp page or false to reverse it. Commented Apr 17, 2013 at 8:25
  • It still doesnt work and still see the confirmDialog as a regular div at start. Shouldnt it be invisible at start and visible on click? Commented Apr 17, 2013 at 8:40
  • ok then , hide the div tag initially by setting the CSS as display:none.later when the button is clicked change it back. Commented Apr 17, 2013 at 8:42

1 Answer 1

1

Start by taking the Confirmation function out of the block. Edited to make it actually work:

<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" />
Sign up to request clarification or add additional context in comments.

3 Comments

Confirmation dialog shows up now but when click confirm asp.net serverside click event doesnt fire.
Maybe you should check this thread: stackoverflow.com/questions/6049687/…
thank you i solved the issue with doPostBack. The post you gave link to, gave me the idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.