Confirm before postback in grid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I have a grid of users, with a button column that does a delete. Is there anyway I can have an "Are you sure?" javascript dialog box in there between the button click and the postback to the OnItemCommand delegate?

Thanks

Dan.
 
Dan,


put this javascript function on the client side of your aspx page
<script>
function confirmSubmit() { var sure=confirm("Are you sure you want to
delete?");
if (sure) return true ;
else
return false ;
}
</script>

and in the ItemdataBound event

if(e.Item.ItemType != ListItemType.Header &&
e.Item.ItemType!= ListItemType.Footer)
{
//for eg :
//Now, reference the LinkButton control that the ButtonColumn for
delete
LinkButton BtnDelete = e.Item.Cells[0].Controls[0];

BtnDelete.Attributes("onclick") = "confirmSubmit() ;"

}
This will do it.If you want to display an item value in the confirm
box modify the javascript and pass an argument with
e.Item.DataItem.

Hope this helps.
Regards,
Marshal Antony
http://dotnetmarshal.com





Dan said:
Hi, I have a grid of users, with a button column that does a delete. Is
there anyway I can have an "Are you sure?" javascript dialog box in there
between the button click and the postback to the OnItemCommand delegate?
 
Back
Top