Feed on
Posts
Comments

Have you tried using JavaScript confirm() function in ASP.NET Button, LinkButton or ImageButton client onclick property?

<asp:LinkButton ID="lbtnDelete" runat="server" CommandName=’DeleteItem’ Text=’Delete’ OnClientClick="confirm (’Are you sure you want to\ndelete this item?’);" ></asp:LinkButton>

But even if you click OK in the confirm dialog the page is not submited because the next JavaScript code for submitting the page (like WebForm_DoPostBackWithOptions) is not executed. The solution is using:

if(!confirm(‘your text’)) return false;

Instead of the code above I use:

<asp:LinkButton ID="lbtnDelete" runat="server" CommandName=’DeleteItem’ Text=’Delete’ OnClientClick="if(!confirm (’Are you sure you want to\ndelete this item?’))return false;" ></asp:LinkButton>

, , ,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • dzone
  • Netscape
  • digg
  • YahooMyWeb
  • Technorati

3 Responses to “Using JavaScript confirm() in ASP.NET control OnClientClick property”

  1. on 03 May 2007 at 11:06 pm Stephen McCulloch

    It seems counterintuitive to use
    if(! confirm(…) ) return false;

    I would prefer to use
    if(confirm(…) ) return true;
    or even
    return confirm(…);

    But those options do not work. I tried.

    Thank you for your solution. It did work.

  2. on 25 Jul 2007 at 3:23 pm stefano

    Very useful!!! Fabio
    you’ve solved my problem, Stefano.
    Thank you Ivan

  3. on 11 Nov 2007 at 6:11 pm software_outsourcer

    Thank you Ivan for short usefull tip..

Trackback URI | Comments RSS

Leave a Reply

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 5 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a