Reputation: 1007
I have a gridview
, and a linkbutton
on this gridview.
When linkbutton is clicked, rowCommand
fires, however I want to ask user to comfirm the click with a comfirmation box,
I couldn't find a way to it.
Upvotes: 2
Views: 5408
Reputation: 1886
in my code behind:
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton del = e.Row.Cells[2].Controls[0] as LinkButton;
del.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this role?');");
}
and in my markup:
<asp:GridView
ID="GridViewRoles"
runat="server"
Width="350px"
EmptyDataText="No Roles"
AutoGenerateColumns="False"
AllowPaging="False"
PageSize="50"
AllowSorting="True"
CssClass="gridview"
AlternatingRowStyle-CssClass="even"
OnRowCommand="GridViewRoles_RowCommand"
OnRowDataBound="GridViewRoles_RowDataBound"
OnRowDeleting="GridViewRoles_RowDeleting" OnRowEditing="GridViewRoles_RowEditing">
<Columns>
<asp:BoundField DataField="Role" HeaderText="Role" SortExpression="Role" HeaderStyle-Width="170px" HeaderStyle-HorizontalAlign="Left" />
<asp:ButtonField CommandName="Edit" Text="Edit" HeaderStyle-Width="50px" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<AlternatingRowStyle CssClass="even" />
</asp:GridView>
Upvotes: 0
Reputation: 3274
try this.
if (e.Row.RowType == DataControlRowType.DataRow){
LinkButton link = (LinkButton)e.Row.FindControl("LinkButton1");
link .Attributes.Add("onclick", "return confirm('Are you sure to proceed with this
action?');");
}
Upvotes: 2
Reputation: 460288
Add this as the LinkButton's OnClientClick
property:
OnClientClick="return confirm('Do you really want?');"
Upvotes: 7