OnClientClick confirm delete

14 posts, 0 answers
  1. David
    David avatar
    3 posts
    Member since:
    Nov 2008

    Posted 11 Mar 2009 Link to this post

    All,

    I have a delete button inside a RadAjaxPanel:

    <asp:Button id="btnDelete" Text="Delete" OnClientClick="return confirm('Are you sure you want delete this?');" runat="server"/>

    The js popup is working, but it is not running the server-side click event attached to button.  Take away the OnClientClick, the server-side event runs fine.

    What am I doing wrong?

    Cheers,
    Dave
  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 13 Mar 2009 Link to this post

    Hello David,

    Please try modifying your code as below:

    <asp:Button id="btnDelete" Text="Delete" runat="server"/  
       OnClientClick="if(!confirm('Are you sure you want delete this?')) return false;"/> 

    Find more about client confirmation and ajax here.

    Kind regards,
    Iana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andreas Botsikas
    Andreas Botsikas avatar
    5 posts
    Member since:
    Mar 2004

    Posted 29 Apr 2009 Link to this post

    Hi,

    I would like to translate this message: 'Are you sure you want to delete this?' in the languages my site uses. So could you tell me how can I modify the following statement using Resources but only for the question and not for the whole string.

    OnClientClick="if(!confirm('Are you sure you want delete this?')) return false;"

     
     Thanksss,
    Andreas.




  5. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 29 Apr 2009 Link to this post

    Hi Andreas,

    In this case you could assign the button OnClientClick property server side, for instance as below:

    protected viod Page_Load(object, sender, EventArgs e)     
    {     
        string deleteMessage = "";     
        //retrieve the delere message from the Resource file     
        btnDelete.OnClientClick = "if(!confirm('" + delteMessage + "')) return false;";     
    }   

    I hope this helps.

    All the best,
    Iana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Tonino
    Tonino avatar
    107 posts
    Member since:
    Nov 2007

    Posted 09 Jun 2009 Link to this post

    Hello

    I'm using this approach in the aspx file:
     OnClientClick=<%# String.Format("if(!confirm('{0}'))return false;", Resources.GlobalRes.btnDeleteSelected_ConfirmText)%>

    It works when you do a DataBind() in the code behind eg. in page_load.

    Tonino.



  7. Eliza Sahoo
    Eliza Sahoo avatar
    29 posts
    Member since:
    Jan 2010

    Posted 17 Feb 2010 Link to this post

    Hi all,
        1. Here we have a function The 'ConfirmDelete()' which is executed each time a click event occurs on the page.
    2. Then we use a logic that to find which element was clicked on i.s we append a word 'DELETE' to the ID of the control.
    3.And finally check if the clicked element having ID is 'DELETED' , then the javascript function will be execute to ask the user about his/her confirmation.
     
    JavaScript code:
     
     function ConfirmDelete(e) 
    {    
    var targ;

    if (!e)
    {   
    var e = window.event;
    }
    targ = (e.target) ? e.target : e.srcElement;

    if (targ.nodeType == 3) 
    {
    targ = targ.parentNode;
    }

    if (targ.id.toLowerCase().indexOf("delete") >= 0) 
    {        
    return confirm("Do you want to delete this item?");
    }
    routeEvent(e);
    }  
    document.onclick = ConfirmDelete;
     
    aspx  code:

    <asp:GridView RunAt="server" ID="gvTest" DataSourceID="SqlDataSource1">
    <Columns>       
    <asp:TemplateField>
    <ItemTemplate>
    <asp:LinkButton runat="server" 
    ID="DeleteMe" Text="Delete" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
     Hope this was helpful.

  8. Bala
    Bala avatar
    11 posts
    Member since:
    Aug 2012

    Posted 21 Jun 2012 Link to this post

    <asp:Button id="btnDelete" Text="Delete" runat="server"/  
       OnClientClick="if(!confirm('Are you sure you want delete this?')) return false;"/> 

    this worked for me, my page is surrounded by radajaxpanel with radloading panel & also i have server side onclick event for a button.

    The above one worked for me rather than using btn.Attributes.Add("OnClick","return confirm();"); It invokes the condifrm prompt and after receiving the request it triggers the server side code for that button.
  9. Elias
    Elias avatar
    12 posts
    Member since:
    Apr 2009

    Posted 03 May 2013 Link to this post

    Hello, I try this scenario but a little bit different, I want to the confirm window looks as telerik radconfirm. I change the code loke this:
    <asp:Button ID="btnDelete" runat="server"="if(!radconfirm('Are you sure you want delete this?')) return false;" Text="DELETE"    />

    The radconfirm shows but disappear matters of a blink of the eye.  I don't know why. Any thoughts? my version is 2010.1.415.35
  10. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 May 2013 Link to this post

    Hi,

    Try modifying the code as shown below.
    aspx:
    <asp:Button ID="btnDelete" Text="Delete" runat="server" OnClientClick="ShowDialog(this); return false;"/>
    JS:
    function ShowDialog(btn) {
           radconfirm("are you sure you want to delete this?");
       }

    Thanks,
    Shinu
  11. Elias
    Elias avatar
    12 posts
    Member since:
    Apr 2009

    Posted 17 May 2013 Link to this post

    Thanks for the reply. The dialog works but when I press the Ok button not fire the btnDelete_Click
    event

    aspx
    <asp:Button ID="btnDelete" Text="Delete" runat="server" OnClientClick="ShowDialog(this); return false;" OnClick="btnDelete_Click"/>

    jscript
    function ShowDialog(btn) {
        radconfirm("are you sure you want to delete this?");

    c#
    protected void btnDelete_Click(object sender, EventArgs e)
           {
              DeleteRecord()
           }

    any thoughts?
  12. Edward
    Edward avatar
    13 posts
    Member since:
    Sep 2011

    Posted 18 May 2013 Link to this post

    function OnClientClicked(button, args)
    {
        if (window.confirm("Do you want to do this postback?"))
        {
            button.set_autoPostBack(true);
        }
        else
        {
            button.set_autoPostBack(false);
        }
    }

    You can use the function above, and 
    OnClientClick="ShowDialog(this); return false;" 
    should be
    OnClientClicked="OnClientClicked"

    -Ed
  13. Elias
    Elias avatar
    12 posts
    Member since:
    Apr 2009

    Posted 20 May 2013 Link to this post

    Thanks for the reply, do all respect, this workaround does not work. onClientClicked is not an event for asp button or maybe I dont understand what you can achieve with this solution.
  14. Angel Petrov
    Admin
    Angel Petrov avatar
    1007 posts

    Posted 22 May 2013 Link to this post

    Hi Elias,

    Actually Ed was probably referring to the OnClientClicked event of the RadButton. In attachments you can find a runnable sample which demonstrates a possible implementation of the described scenario.

    Regards,
    Angel Petrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  15. Elias
    Elias avatar
    12 posts
    Member since:
    Apr 2009

    Posted 22 May 2013 Link to this post

    Oh, ok. Thanks for the reply. I use a quite old dll (2010) for that reason I use the asp button, (I dont have the radbutton in that dll.) but thanks anyways
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017