Hi Jerry,
As for DataGrid/GridView's button field confirm javascript, I always use
the following kind of confirm statement:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lb = e.Row.FindControl("LinkButton1") as LinkButton;
if (lb != null && lb.Text == "Edit")
{
lb.OnClientClick = "if(confirm('are you sure to
edit?')==false){return false;}";
}
}
}
It works well on both datagrid and GridView on my local test pages. You can
also try it to see whether it works.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: =?Utf-8?B?SmVycnkgQw==?= <jerryed@nospam.nospam>
>Subject: gridview CommandField Delete Jave script confirm on OnClientClick
>Date: Thu, 27 Mar 2008 08:40:02 -0700
>I have a gridview on a clientcontrol .ascx I am using the tutorial22 from
>MSDN and it is not working. The jave confirm box comes up but when I click OK
[quoted text clipped - 21 lines]
>
>Thank you
Jerry C - 28 Mar 2008 14:37 GMT
Steven,
Good to here from you, Thenk you for the reply.
I am using that code but the object is a button instead of a linkbutton.
I changed the grid from using a CommandField to TemplateField with a button
and it works. It must be using a button in the commandfield instead of a
linkbutton.
I think adding java script to the button makes the postback not work.
Any way using the TemplateFiled works so I am moving on.
Thank you

Signature
Jerry
> Hi Jerry,
>
[quoted text clipped - 65 lines]
> >
> >Thank you
Steven Cheng [MSFT] - 31 Mar 2008 02:15 GMT
Thanks for your reply Jerry,
I'm glad that you've got it working.
Good luck!
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
--------------------
>From: =?Utf-8?B?SmVycnkgQw==?= <jerryed@nospam.nospam>
>References: <611C464C-CDB5-46B1-A8D8-8D9F75FF7E9E@microsoft.com>
<zEqWlzHkIHA.1500@TK2MSFTNGHUB02.phx.gbl>
>Subject: RE: gridview CommandField Delete Jave script confirm on OnClientCl
>Date: Fri, 28 Mar 2008 06:37:00 -0700
>Steven,
>
[quoted text clipped - 38 lines]
>>
>> Microsoft MSDN Online Support Lead