tags:

views:

494

answers:

1

Asp.Net 3.5 / WebForms (no ajax)

I am trying to update a delete confirm box with jquery & UIBlock. Old code looks something like this...

<asp:LinkButton OnClientClick="return confirm('Are you sure you want to delete?')" runat="server" ID="DeleteButton" OnClick="DeleteButton_OnClick">Delete</asp:LinkButton>

What is the best practice to postpone and then continue a postback with jquery & asp.net? I haven't found a clean way/example/guidance on this. Dave Ward (encosia.com) has some examples w/ UIBlock but none of them uses UIBlock as a confirmation / modal popup.

Thanks for any help/pointers.

Answer

<a href="#" id="delete">
  <span>Delete?</span>
</a>

<div id="question" style="display:none; cursor: default"> 
        <h1>Are you sure you want to delete?</h1> 
        <asp:LinkButton runat="server" Text="Yes" OnClick="DeleteButton_OnClick"></asp:LinkButton>
        <a href="#" id="no"><span>No</span></a>
</div> 


<script type="text/javascript">
    $(document).ready(function() {

      $('#delete').click(function(ev) {
        ev.preventDefault();
        $.blockUI({ message: $('#question'), css: { width: '275px'} });
      });

      $('#no').click(function() {
        $.unblockUI();
        return false;
      });

    }); 
</script>
+1  A: 

Hi,

You can do something like this :

$('#DeleteButton').bind('click', function() {

   // if confirmation button inside the form is pressed ..
   $('#confirm_button').bind('click', function() {
    // redirect to the page where it resolves the request  
        window.location = "http://www.site.com/?delete";
        // or use ajax call
    $.ajax({
     // the request to delete 
    });
        // this one in case you choose to make ajax request
    $.unblockUI();
   });

   $.blockUI({
        // form setted with display:none; in css to be trigged when delete button is clicked
        // css here is an example
    message: $('#delete_form'),
    css: { 
     border: 'none', 
     padding: '15px',
     width: '400px',
     backgroundColor: '#000', 
     '-webkit-border-radius': '10px', 
     '-moz-border-radius': '10px',
     color: '#fff' 
     }
    });

        // cancel button inside the form, when clicked, dismiss form 
    $('#cancel').click($.unblockUI);
        // if user clicks outside the form, it dismisses the form as well
    $('.blockOverlay').click($.unblockUI); 
});
yoda
I am using standard web forms,no ajax or rest services.
B Z
Please take more attention to the answers .. this example works like simple forms as well.
yoda
@yoda, maybe I am not understanding the example. How do you callback to complete the delete action after blockui > confirm?
B Z
window.location = "http://www.site.com/?delete";
yoda
that is what I had thought. the problem is I don't have a page that manages deletes, or have any rest services for it. I just want to continue the postback initiated so I can handle the delete in the page's method. After some more digging, i think what I need is "Page.ClientScript.GetPostBackEventReference" I will try it tomorrow @ work.
B Z
I got it now...silly me was trying to make this more complex than it need be. The visible display button is just a standard html button. The button inside the confirmation is an asp.net linkbutton, so when "Delete Yes" is clicked, the postback occurs.
B Z