locked
repeater delete command confirm popup for user input RRS feed

  • Question

  • User-2012806367 posted
     

    Hi

    I have added AJAX to my web site and have looked at the various control extenders such as confirm button extender, modal popup extender, etc. They all seem to be linked to a specific control on the page – ie – a button, link button, etc. which the control name is know at design time.


    What I want to do is using client side coding (java? Ajax?) have a confirming popup if the user selects the delete command (see the code snippet taken from a repeater control). Highlighted below that in red, you can see the name of the repeater linkButton changes thus none of the Ajax extenders seem to work.


    Summarizing, if one of the delete linkButtons is pressed by the user, the Javascript should intercept the postback, create a popup that tests the user to ensure the delete command should be carried out, close the popup and allow the postback to proceed normally. If the user aborts the delete command, then the popup should close and no further action take place.


    Is there somewhere I can find code such as this or have I misunderstood the Ajax entenders? Or can some Java guru write the code for me (I know very little about Javascript). (I have been using VB code behind but I think what I require should reside on the .aspx page)


    Thanks in advance for your help and have a nice day.



    <td style="border-bottom:1px solid #808080" align="left">

    <asp:LinkButton ID="btnEdit" runat="server"

    CommandName="Edit"

    CommandArgument=<%#CreateDetailString(Ctype(Container.DataItem, Data.DataRowView).Item(0)) %>

    >Edit

    </asp:LinkButton>

    <asp:LinkButton ID="btnDelete" runat="server"

    CommandName="Delete"

    CommandArgument=<%#CreateDetailString(Ctype(Container.DataItem, Data.DataRowView).Item(0)) %>

    >Delete

    </asp:LinkButton>

    <%#CType(Container.DataItem, Data.DataRowView).Item(1) %>

    </td>




    <a id="ctl00_ContentPlaceHolder1_Repeater1_ctl00_btnEdit" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Repeater1$ctl00$btnEdit','')">Edit

    </a>

    <a id="ctl00_ContentPlaceHolder1_Repeater1_ctl00_btnDelete" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Repeater1$ctl00$btnDelete','')">Delete

    </a>


    <a id="ctl00_ContentPlaceHolder1_Repeater1_ctl01_btnEdit" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Repeater1$ctl01$btnEdit','')">Edit

    </a>

    <a id="ctl00_ContentPlaceHolder1_Repeater1_ctl01_btnDelete" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Repeater1$ctl01$btnDelete','')">Delete

    </a>

    <a id="ctl00_ContentPlaceHolder1_Repeater1_ctl02_btnEdit" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Repeater1$ctl02$btnEdit','')">Edit

    </a>

    <a id="ctl00_ContentPlaceHolder1_Repeater1_ctl02_btnDelete" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Repeater1$ctl02$btnDelete','')">Delete

    </a>

    Wednesday, March 14, 2007 6:55 PM

Answers

  • User-1344500788 posted

    if u'd like to use custom confirmation ( like jquery dialog,bootboxjs etc.. ) then you have to generate button's "postback string" or get it somehow. asp.net gives such as postback name after rendering the page; **__doPostBack('ctl00$ContentPlaceHolder1$btnDeleteSelected','')**. after realizing this i wrote a js function which is generates button's postback str;

        function PostBackBtnMake(id) { // id : ContentPlaceHolder1_btnDeleteSelected
        var result;
        var temp = id.split('_');
        result = 'ctl00$' + temp[0] + '$' + temp[1];
        return result;
    }

    then i be able to use in custom confirmation box (in this case i used bootboxjs);


        function PostBackBtn(e) {
        var _result = false;
        bootbox.confirm("Are you sure?", function (result) {
            if (result) {
                __doPostBack(PostBackBtnMake(e.id), '')
            }
        });

        return _result;
    }


    it's worked for me, i hope it helps you too.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 3, 2014 10:29 PM

All replies

  • User-1649476877 posted

    Hello,

     I presume this will be something like the gridview control in that when a particular row is bound, you can recieve an event for it, and touch the attributes of each control for that "row", or in this case, data cell, or whatever.

     The trick is going to be catching the delete button before it even renders out to the client, and then attaching to it an onclick="" event handler. Take a look at the confirm() javascript method to see how it works, but your onclick method would be something like <a href="blah..htm" onclick="return confirm('do you want to?');">asdf</a>, or something like that. The confirm() method will return a 1/0 value depending on whether the user clicked OK or cancel, respectively. Returning a value from the event handler will tell the browser whether to allow the event to trickle (and therefore be caught by anything else); true means bubble, false means don't bubble.

    Is that something like you wanted?

    Thursday, March 15, 2007 3:01 AM
  • User-2012806367 posted

    Hi

    Thanks for the quick reply.  Sounds good to me. Unfortunately, not being a Java programmer, most of what you said is Greek to me.  If I understand what you said, I would attach an onclick event handler to  [  ctl00$ContentPlaceHolder1$Repeater1$ctl00$btnDelete ] which would intercept the button press on the web page, raise a confirm dialog box and if yes, tell the browser to postback the page and if no, no postback.  This is what I want to do.

    Using a repeater, each instance of [  ctl00$ContentPlaceHolder1$Repeater1$ctl00$btnDelete ] link button has a different name (ct100 changes to ct101, ct102, etc), I am not sure how to attach an onclick event to these controls. 

    It would seem to me that the browser would know which repeater linkbutton has been pressed and would pass this information back to the server.  Perhaps, somehow, I would need to intercept this information, check for my linkbutton, if it is present, raise the confirm dialog box and either allow or stop the postback all using client side code.   If the linkbutton pattern highlighted in red is not present, the postback would proceed.

    Does this clairify for you  what I need?

    Thanks and have a nice day. 

     

    Thursday, March 15, 2007 10:00 AM
  • User-1649476877 posted
    Hello,

    I just blogged about it for you here: http://www.ben-rush.net/blog/PermaLink,guid,483286ef-b883-421f-8ede-cbd35c8b5e85.aspx. I figured if anyone else ever wants to know they can just find it online now (if it's not there already).
    Thursday, March 15, 2007 12:28 PM
  • User-2012806367 posted

    HI

    I spent the afternoon looking at Java (which I know almost nothing about - [|-) ]the learning curve is steep and becomming more necessary every day) and  tried to modify your code:

    protected void GridView_Views_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
       ImageButton button =
          (ImageButton)e.Row.Cells[0].Controls[0];
       button.Attributes.Add(
          "onclick", "if(!confirm('Delete this item?'))return false;");

       return;
    }
    return;
    }

    to

    protected void RepeaterApprove_Views_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
       ImageButton button =
          (ImageButton)e.Row.Cells[0].Controls[0];
       button.Attributes.Add(
          "onclick", "if(!confirm('Delete this item?'))return false;");

       return;
    }
    return;
    }

    No luck.  What am I missing.

    Thanks and have a nice day. 

     

    Thursday, March 15, 2007 4:09 PM
  • User-2012806367 posted

    Hi

    I finially figured out how to make this work.

    <asp:LinkButton ID="btnDelete" runat="server"

    OnClientClick="javascript:if(!confirm('Delete this item?'))return false;"

    CommandArgument="<%#CreateDetailString(Ctype(Container.DataItem, Data.DataRowView).Item(0))%>"

    CommandName="Delete">Delete</asp:LinkButton>

    I added the OnClientClick="...  to the linkbutton.  Then I needed to remember both the item template and alternating template.

    Now the confirm popup is always executed for each delete command within the repeater.

    Thanks for the help.  Been a good learning experience.  The javascript statement and where to locate it supplied by Ben Rush helped greatly.

    Have a nice day.

    Friday, March 16, 2007 7:40 AM
  • User-1344500788 posted

    if u'd like to use custom confirmation ( like jquery dialog,bootboxjs etc.. ) then you have to generate button's "postback string" or get it somehow. asp.net gives such as postback name after rendering the page; **__doPostBack('ctl00$ContentPlaceHolder1$btnDeleteSelected','')**. after realizing this i wrote a js function which is generates button's postback str;

        function PostBackBtnMake(id) { // id : ContentPlaceHolder1_btnDeleteSelected
        var result;
        var temp = id.split('_');
        result = 'ctl00$' + temp[0] + '$' + temp[1];
        return result;
    }

    then i be able to use in custom confirmation box (in this case i used bootboxjs);


        function PostBackBtn(e) {
        var _result = false;
        bootbox.confirm("Are you sure?", function (result) {
            if (result) {
                __doPostBack(PostBackBtnMake(e.id), '')
            }
        });

        return _result;
    }


    it's worked for me, i hope it helps you too.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 3, 2014 10:29 PM