Confirm Extender for ButtonField

  • Thread starter Thread starter Elmo Watson
  • Start date Start date
E

Elmo Watson

I know how to add a confirmation or an AJAX extender to a regular button,
but is there any way to add a confirm (yes/no) to a ButtonField in a
Gridview?
 
Hi elmo,

Unfortunatelly you cannot use ButtonField with ConfirmButtonExtender without
extra coding, insead i'd recommend using templatefield:

<asp:GridView runat="server" ID="gv" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button runat="server" ID="btnDelete" Text="Delete"
CommandName="Delete" />
<ajaxtoolkit:confirmbuttonextender id="cbe" runat="server"
targetcontrolid="btnDelete"
confirmtext="Are you sure you want to delete this record?" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


or even better, why not just using templatefield with a button (no
confirmbuttonextender needed):

<asp:GridView runat="server" ID="gv" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button runat="server" ID="btnDelete"
Text="Delete"
CommandName="Delete" OnClientClick="return
confirm('really?');" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
 
Back
Top