In my asp.net application am having a master page and some other pages, in that pages I’ve add button as well as delete button, for this delete button I’ve written the delete method in my code behind, its working fine. But before this delete function fires I need to display a delete confirmation box. For this I’ve written delete confirmation method in the jQuery file named custom.js under Js folder, and am referring this js file in the master page like
<script src="/Js/custom.js" type="text/javascript"></script>
in this custom.js I’ve written the delete confirmation method under pageInit of custom.js like
function pageInit(){
$(".delete").click(function (event) {
confirmationBox(event);
});
}
function confirmationBox(event) {
var r = confirm("You are about to delete some items. Click Ok to continue");
if (r == true) {
$(document).submit();
}
else {
event.preventDefault();
}
}
and in the scripting am using the class name as delete like
<asp:Button ID="btnDelete" class="delete" Text="Delete"/>
from the script am calling the js file as
<script type="text/javascript">
$(document).ready(function () {
pageInit();
});
</script>
but this delete confirmation method is not firing at all, whats wrong with this query, can anyone help me…..
Another way to implement what you are doing is by using the
OnClientClickevent of the ASP.NET Buttonand that should do it 🙂
[Update]
My bad, I forgot to include return on the
OnClientClickfunction;the
returnstops the postback from happening if you choose cancel on the confirmation.