Confirm before postback in grid

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.
 
M

Marshal Antony

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top