views:

34

answers:

2

I've the Javascript code to do a confirmation before deletion of some records

function confirmDelete()
{
   if(confirm('Delete all?'))
   {
      return true;
   }
   else
   {
      return false;
   }
}

I've the button code here

<asp:Button ID="btnDelete" runat="server" onClientClick="return confirmDelete();" onClick="btnDelete_click" />

If i've the button outside an update panel (basically i'm using RadAjaxPanel by Telerik) it is working fine. But when the button is inside an ajax panel, even if i click OK for deleting the records the server side code is not called.

Any ideas?

A: 

Okie, should have searched for some time. Got the answer here - http://forums.asp.net/p/1486636/3482994.aspx. Dint know about that!

NLV
+1  A: 

Your code is being prepended to the click handler that posts the action back to the server. You need to check if your result returns true/false then optionally continue executing the server-generated code.

  <asp:Button ID="btnDelete" runat="server"
              onClientClick="if (!confirmDelete()) { return false; }" 
              onClick="btnDelete_click" />  

This will result in client-side HTML like

 <input type="submit" id="btnDelete"
        onclick="if (!confirmDelete()) { return false; } __DoPostBack... 

allowing the server-generated code to be executed (i.e., no return is evaluated unless the confirmation fails).

tvanfosson
Guess i can thank here. Thank you!! :)
NLV