gridview CommandField Delete Jave script confirm on OnClientClick

Discussion in 'ASP .Net Web Controls' started by Jerry C, Mar 27, 2008.

  1. Jerry C

    Jerry C Guest

    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
    the page does not post back.

    MSDN page:
    http://msdn2.microsoft.com/en-us/library/bb428868.aspx
    Section:
    Step 3: Configuring the OnClientClick Property for the Delete Button in a
    CommandField
    The Jave for the page is:

    <input type="button" value="Delete" onclick="return confirm('Are you sure
    you want to delete this record.
    ');javascript:__doPostBack('PRBPCreativeBrief1$gdApproval','Delete$0')"
    class="ms-topnav" />

    The Java for the confirm is there but the next java for the post back does
    not run.

    The vb code is:
    Dim btnDelete As Button = CType(e.Row.Cells(5).Controls(0), Button)
    btnDelete.OnClientClick = "return confirm('Are you sure you want to delete
    this record. ');"

    Thank you




    --
    Jerry
     
    Jerry C, Mar 27, 2008
    #1
    1. Advertising

  2. 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:
    .

    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------
    >From: =?Utf-8?B?SmVycnkgQw==?= <>
    >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
    >the page does not post back.
    >
    >MSDN page:
    >http://msdn2.microsoft.com/en-us/library/bb428868.aspx
    >Section:
    >Step 3: Configuring the OnClientClick Property for the Delete Button in a
    >CommandField
    > The Jave for the page is:
    >
    ><input type="button" value="Delete" onclick="return confirm('Are you sure
    >you want to delete this record.
    >');javascript:__doPostBack('PRBPCreativeBrief1$gdApproval','Delete$0')"
    >class="ms-topnav" />
    >
    >The Java for the confirm is there but the next java for the post back does
    >not run.
    >
    >The vb code is:
    >Dim btnDelete As Button = CType(e.Row.Cells(5).Controls(0), Button)
    > btnDelete.OnClientClick = "return confirm('Are you sure you want to

    delete
    >this record. ');"
    >
    >Thank you
    >
    >
    >
    >
    >--
    >Jerry
    >
     
    Steven Cheng [MSFT], Mar 28, 2008
    #2
    1. Advertising

  3. Jerry C

    Jerry C Guest

    RE: gridview CommandField Delete Jave script confirm on OnClientCl

    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

    --
    Jerry


    "Steven Cheng [MSFT]" wrote:

    > 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:
    > .
    >
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    > --------------------
    > >From: =?Utf-8?B?SmVycnkgQw==?= <>
    > >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
    > >the page does not post back.
    > >
    > >MSDN page:
    > >http://msdn2.microsoft.com/en-us/library/bb428868.aspx
    > >Section:
    > >Step 3: Configuring the OnClientClick Property for the Delete Button in a
    > >CommandField
    > > The Jave for the page is:
    > >
    > ><input type="button" value="Delete" onclick="return confirm('Are you sure
    > >you want to delete this record.
    > >');javascript:__doPostBack('PRBPCreativeBrief1$gdApproval','Delete$0')"
    > >class="ms-topnav" />
    > >
    > >The Java for the confirm is there but the next java for the post back does
    > >not run.
    > >
    > >The vb code is:
    > >Dim btnDelete As Button = CType(e.Row.Cells(5).Controls(0), Button)
    > > btnDelete.OnClientClick = "return confirm('Are you sure you want to

    > delete
    > >this record. ');"
    > >
    > >Thank you
    > >
    > >
    > >
    > >
    > >--
    > >Jerry
    > >

    >
    >
     
    Jerry C, Mar 28, 2008
    #3
  4. RE: gridview CommandField Delete Jave script confirm on OnClientCl

    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==?= <>
    >References: <>

    <>
    >Subject: RE: gridview CommandField Delete Jave script confirm on OnClientCl
    >Date: Fri, 28 Mar 2008 06:37:00 -0700


    >
    >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
    >
    >--
    >Jerry
    >
    >
    >"Steven Cheng [MSFT]" wrote:
    >
    >> 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
    >>
    >>
     
    Steven Cheng [MSFT], Mar 31, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Johann
    Replies:
    0
    Views:
    718
    Johann
    Aug 3, 2006
  2. Replies:
    1
    Views:
    822
  3. gnewsgroup
    Replies:
    0
    Views:
    1,052
    gnewsgroup
    Dec 13, 2007
  4. dddan
    Replies:
    2
    Views:
    1,030
    David C
    Dec 14, 2007
  5. Mauricio Pires

    OnClientClick with confirm doesn't work

    Mauricio Pires, Jan 8, 2009, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    1,207
    Jester98x
    Jan 21, 2009
Loading...

Share This Page