How can we use alert and confirm method in asp.net application.
i am working with application where i want to use confirm box before
going for any operation. and same for alert box
Sonu
Dealing with popup windows can be tricky and not safe (popup blockers
may negate your efforts.)
The easiest way would be to employ the "confirm" statement in
client-side javascript.
For example, consider the most common case - adding a confirmation
dialog when user attempts to delete a record from a datagrid (gridList
below) on ASP.NET page. The server-side event handler will only
execute if the user clicks "yes" on the client-side, causing the event
to fire:
In your HTML:
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton id="linkDelete" runat="server"
CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
In your code behind:
// The below will add a confirmation dialog
// to each linkDelete instance at runtime
private void gridList_ItemDataBound(object sender,
DataGridItemEventArgs e )
{
if( e.Item.FindControl("linkDelete") !+ null )
{
LinkButton deleteButton =
e.Item.FindControl("linkDelete") as LinkButton;
deleteButton.Attributes.Add( "onclick",
@"javascript:return confirm('Are you sure you want to delete this
record?');" )
}
}
private void gridList_DeleteCommand( object source,
DataGridCommandEventArgs e )
{
// Delete the record here
}