I have a standard ASP.NET 2.0 web page with a Delete button on it. What I need and can't figure out how to pull off is when the user presses the delete button a confirm dialog popups asking the user "are you sure?". If the user says yes then I want to disable the delete button and perform a postback that will run the server side code deleteButton_Click.
Here is the tag:
<asp:Button ID="deleteButton" Text="Delete" OnClick="deleteButton_Click" runat="server" />
Here is the javascript (in jquery) to handle the client side click:
var deleteButton = $(input.eq(0));
deleteButton.click( function()
{
var a = confirm( "Are you sure you want to delete this item?" );
if ( a == false )
{
return false;
}
else
{
deleteButton.attr( "disabled", "disabled" );
__doPostBack( deleteButton.attr( "id" ), "" );
}
} );
The confirm dialog works as expected and the disabling works ok too. The form does postback fine but it does not run the deleteButton_Click event handler. The __doPostBack javascript code does exist on the page.
I could add UseSubmitBehavior="false" to the deleteButton tag but then it would ignore the confirm dialog answer.
So maybe I'm asking too much of ASP.NET here. Any ideas how to make this work?
Thanks,
Craig
Thanks for the feedback but it was a fairly simple solution.
The javascript line should be:
__doPostBack( deleteButton.attr( "name" ), "" );
instead of:
__doPostBack( deleteButton.attr( "id" ), "" );
I didn't realize that the "name" attribute is the one that doPostBack method was looking for.