While deleting, I used the 'adding a delete prompt' example.
protected void OnItemDataBoundHandler(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem dataItem = e.Item as GridDataItem;
string CreateDate = dataItem["CreationDate"].Text;
LinkButton button = dataItem["DeleteColumn"].Controls[0] as LinkButton;
button.Attributes[
"onclick"] = "return confirm('Are you sure you want to delete Item created on " +
CreateDate +
"?')";
}
...this works well...although I'm unsure of the way to receive the response from the "onclick" event..
thanks,
minh Bui
6 Answers, 1 is accepted
I guess you are following the steps suggested in this documentation topic (section 'Display confirmation dialog with text including column cell value'). If so, the confirm method executed in this way should automatically cancel the delete if the user choose 'No' and process the deletion in case 'Yes' is selected.
Regards,
Sebastian
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

I used the radwindow for confirmation and copied the code. It works well although i'm not understanding the way to the user's response back to my code-behind to execute the deletion function.
this is the javascript
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<script type="text/javascript">
function confirmCallBackFn(arg) {
radalert("Confirm returned the following result: " + arg);
}
</script>
this is the code behind that executes the javascript
if (e.Item is GridDataItem)
{
GridDataItem dataItem = e.Item as GridDataItem;
string CreateDate = dataItem["CreationDate"].Text;
LinkButton button = dataItem["DeleteColumn"].Controls[0] as LinkButton;
button.Attributes["onclick"] = "radconfirm('Are you sure?', confirmCallBackFn); return false;";
//if yes how to call deleterow(); //routine to delete row
}
thanks,
Minh Bui

<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
telerik:RadWindowManager
ID
=
"windows1"
runat
=
"server"
/>
<
script
type
=
"text/javascript"
>
var oldConfirm = radconfirm;
window.radconfirm = function (text, mozEvent) {
var ev = mozEvent ? mozEvent : window.event; //Moz support requires passing the event argument manually
//Cancel the event
ev.cancelBubble = true;
ev.returnValue = false;
if (ev.stopPropagation) ev.stopPropagation();
if (ev.preventDefault) ev.preventDefault();
//Determine who is the caller
var callerObj = ev.srcElement ? ev.srcElement : ev.target;
//Call the original radconfirm and pass it all necessary parameters
if (callerObj) {
//Show the confirm, then when it is closing, if returned value was true, automatically call the caller's click method again.
var callBackFn = function (arg) {
if (arg) {
callerObj["onclick"] = "";
if (callerObj.click) callerObj.click(); //Works fine every time in IE, but does not work for links in Moz
else if (callerObj.tagName == "A") //We assume it is a link button!
{
try {
eval(callerObj.href)
}
catch (e) { }
}
}
}
oldConfirm(text, callBackFn, 300, 100, null, null);
}
return false;
}
</
script
>
</
div
>
<
div
>
<
telerik:RadScriptManager
runat
=
"server"
ID
=
"RadScriptManager1"
>
</
telerik:RadScriptManager
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"false"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
AllowFilteringByColumn
=
"true"
OnDeleteCommand
=
"RadGrid1_DeleteCommand"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"ID"
HeaderText
=
"ID"
UniqueName
=
"ID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
Text
=
"Delete"
CommandName
=
"Delete"
OnClientClick
=
"return radconfirm('Are you sure you want to delete this record?', event);"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
div
>
</
form
>
</
body
>
Thanks,
Jayesh Goyani

I'm assuming that the button
<
asp:Button
ID
=
"Button1"
runat
=
"server"
Text
=
"Delete"
CommandName
=
"Delete"
OnClientClick
=
"return radconfirm('Are you sure you want to delete this record?', event);"
/>
will fire the radgrid on delete event....I've tried this and the delete event is failing to fire...this is my code
<telerik:RadGrid ID="RadGrid1" GridLines="None" AutoGenerateColumns="False"
runat="server" AllowPaging="True" AllowSorting="True"
OnItemDataBound="OnItemDataBoundHandler"
AllowAutomaticUpdates="True" AllowAutomaticInserts="True"
ShowStatusBar="True" AllowFilteringByColumn="True"
CellSpacing="0" EnableAJAX="True" onneeddatasource="RadGrid1_NeedDataSource"
oninsertcommand="RadGrid1_InsertCommand"
onupdatecommand="RadGrid1_UpdateCommand"
ondeletecommand="RadGrid1_DeleteCommand">
<
telerik:GridTemplateColumn>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Delete" CommandName="Delete"
OnClientClick="return radconfirm('Are you sure you want to delete this record?', event);" />
</ItemTemplate>
</telerik:GridTemplateColumn>
protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
{
string test = "";  
}
thanks,
Minh Bui

Please download project from below link and check whats wrong with your code.
Replacing the default confirm dialog for RadGrid with RadWindow confirm
let me know if any concern.
Thanks,
Jayesh Goyani
