Confirm Dialog server side, with logic for the Telerik ASP.NET RadGrid Template control button

A RadGrid template button may look simple, but the moment you need a clean, reliable confirmation step, the cracks in the default approach start to show. Browser prompts, client-side scripts, RadWindow confirmations—each option behaves a little differently inside a templated control. This article cuts through the noise and shows you the most practical patterns for adding confirmation dialogs to TemplateColumn buttons, from the quick one-liner to the more polished Telerik-style confirm workflow.

Telerik makes this easy because any control inside a GridTemplateColumn can have client-side attributes added directly in the markup.

Below is the simplest and most reliable pattern.

ASPX Markup (TemplateColumn with Confirm)

<telerik:GridTemplateColumn HeaderText="Delete">
    <ItemTemplate>
        <asp:Button ID="btnDelete" runat="server" Text="Delete" CommandName="DeleteItem" OnClientClick="return confirm('Are you sure you want to delete this item?');" />
    </ItemTemplate>
</telerik:GridTemplateColumn>

What this does

  • OnClientClick fires before the postback.

  • return confirm(...) ensures:

    • OK → returns true → postback continues

    • Cancel → returns false → postback is cancelled

If you’re using a LinkButton instead

<asp:LinkButton ID="lnkDelete" runat="server" Text="Delete" CommandName="DeleteItem" OnClientClick="return confirm('Delete this record?');" />

If you need to inject the confirm dynamically (e.g., in ItemDataBound)

This is useful when the message depends on row data.

VB.NET Code-behind

Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
    If TypeOf e.Item Is GridDataItem Then Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
        Dim btn As Button = CType(dataItem.FindControl("btnDelete"), Button)
 
        if btn IsNot Nothing Then
        btn.Attributes("onclick") = "return confirm('Are you sure you want to delete this record?');"
      End If
    End If
End Sub

 

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences