Tuesday, October 19, 2010

MVC Warning users accidental delete

Scenario:
Another requirement, this was for the Grid Control. Multiple records are displayed in the grid and each record had action links to Delete the record.

Client wanted to warn user to avoid accidential delete.

Solution:
JQuery

Script:

 
<script language="javascript" type="text/javascript">
$('div#grid a').each(function () {
if ($(this).text() == 'Delete') {

var originalUrl = this.href;

this.href = '#';

$(this).click(function (el) {

var yesno = confirm("Do you really want to delete.");
if (yesno)
{
window.location = originalUrl;
}
});
}
});
</script>

1 comments:

SMH,  October 25, 2010 at 12:02 AM  

Hi Sandeep,
I have a scenario where, a user cannot delete an image/ page if its link is used anywhere in the site(ie. pages or documents). Any idea or hint to achieve the same in sharepoint 2010, would be really helpful.

Thanks
SMH