On 19 Sep 2005 09:30:14 -0700, "sonu" <kr*******@yaho o.com> wrote:
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:TemplateCo lumn>
<ItemTemplate >
<asp:LinkButt on id="linkDelete " runat="server"
CommandName="De lete">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateCol umn>
In your code behind:
// The below will add a confirmation dialog
// to each linkDelete instance at runtime
private void gridList_ItemDa taBound(object sender,
DataGridItemEve ntArgs e )
{
if( e.Item.FindCont rol("linkDelete ") !+ null )
{
LinkButton deleteButton =
e.Item.FindCont rol("linkDelete ") as LinkButton;
deleteButton.At tributes.Add( "onclick",
@"javascript
:re turn confirm('Are you sure you want to delete this
record?');" )
}
}
private void gridList_Delete Command( object source,
DataGridCommand EventArgs e )
{
// Delete the record here
}