How to show confirmation when i click on RadButton?

15 posts, 0 answers
  1. guruvu
    guruvu avatar
    32 posts
    Member since:
    Sep 2010

    Posted 19 Jan 2011 Link to this post

    Hi,

    I need to show confirmation before performing action when i click on RadButton.

    Please help me...

    Thanks in advance...

  2. Elliott
    Elliott avatar
    391 posts
    Member since:
    May 2010

    Posted 19 Jan 2011 Link to this post

    OnClientClicking
    Sets a name of a JavaScript function that will be called when the RadButton is clicked. The event is cancelable.

  3. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Jan 2011 Link to this post

    Hello,


    I followed Marianne's suggestion and the final code is shown below.

    <script type="text/javascript">
        function OnClientClicking(sender, args) {
            var callBackFunction = Function.createDelegate(sender, function(argument) {
                if (argument) {
                    this.click();
                }
            });
            var text = "Are you sure you want to submit the page?";
            radconfirm(text, callBackFunction, 300, 100, null, "Title");
            args.set_cancel(true);
        }
    </script>

    RadButton mark-up:
    <telerik:RadButton ID="btnToggle1" CssClass="RadButton" runat="server" Text="Checkbox 1"
        OnClientClicking="OnClientClicking" ButtonType="StandardButton"
        OnClick="btnToggle1_Click">
    </telerik:RadButton>



    -Shinu.

  4. Brad
    Brad avatar
    39 posts
    Member since:
    Aug 2010

    Posted 28 Feb 2011 Link to this post

    Why do I get this in my console window?

    args.set_cancel is not a function

  5. Marin Bratanov
    Admin
    Marin Bratanov avatar
    2676 posts
    Member since:
    Jun 2013

    Posted 02 Mar 2011 Link to this post

    Hello Brad,

    Could you please verify that you have added the handler to the OnClientClicking event and not to the OnClientClicked event as the latter is not cancelable.

    The general approach was outlined a few posts back, but for your convenience I will retrace the steps:

    • Add a handler to the OnClientClicking event with the needed arguments (sender and args)
    • In the function prompt the user to confirm the action (via the window.confirm() method for example)
    • use the args.set_cancel() method with the negated result of the confirm as an argument to cancel the postback (or the assigned onClick action in your scenario).

    More information and how to use RadAlert and RadWindow can be found in the new demo of RadButton.

    Regards,

    Marin
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!

  6. Peter
    Peter avatar
    52 posts
    Member since:
    Mar 2012

    Posted 09 May 2012 Link to this post

    Thanks. But why not just have an property called "ConfirmText" or something like this to make this easier?

  7. Marin Bratanov
    Admin
    Marin Bratanov avatar
    2676 posts
    Member since:
    Jun 2013

    Posted 10 May 2012 Link to this post

    Hi Peter,

    The RadConfirm that is used in the example is part of another control - the RadWindowManager. Adding such a property would require that the RadButton silently includes an entire control on the page along with its scripts and stylesheets. The functionality only consists of several lines of JavaScript that can even be easily reused between different buttons and they can also utilize an already existing manager on the page instead of adding a new one that can break some other functionality.


    All the best,
    Marin
    the Telerik team

    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.

  8. Peter
    Peter avatar
    52 posts
    Member since:
    Mar 2012

    Posted 03 Jul 2013 Link to this post

    I've come back to this article 1 year later and I still think there needs to be an easier way to implement a "Are you sure" confirm on a button click.

  9. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Jul 2013 Link to this post

    Hi Peter,

    Please try the following code snippet.

    ASPX:

    <telerik:RadWindowManager  ID="RadWindowManager1"  runat="server">
    </telerik:RadWindowManager>
    <telerik:RadButton  AutoPostBack="false"  ID="RadButton1"  runat="server"  Text="RadButton"  OnClientClicked="OnClientClicked">
    </telerik:RadButton>

    JS:
    <script type="text/javascript">
        function OnClientClicked(button, args)
        {
            window.radconfirm("Are you sure you want to submit the page?");
        }
    </script>

    Please have a look at this Demo.

    Hope this helps.
    Thanks,
    Princy

  10. Kien
    Kien avatar
    2 posts
    Member since:
    Jan 2011

    Posted 11 Nov 2013 Link to this post

    function btnDelete_Clicking(sender, args) {
        args.set_cancel(!confirm("Chắc chắn muốn xóa hợp đồng này ?"));
    }

  11. Smartie
    Smartie avatar
    9 posts
    Member since:
    Jun 2007

    Posted 07 Jan Link to this post

    Princy,

    I have tried your code, I get the window. Pressing okay doesn't cause the button to do it's post back?

    I have set auto post back to false, but are we meant to tell it to do the post back when they confirm it?

    Regards

    Leah

  12. Marin Bratanov
    Admin
    Marin Bratanov avatar
    2676 posts
    Member since:
    Jun 2013

    Posted 07 Jan Link to this post

    Hello Leah,

    The following demo shows three ways to have such a confirmation for RadButton: http://demos.telerik.com/aspnet-ajax/button/examples/confirm/defaultcs.aspx. Please examine it to see how the controls are set up.

    When using standard button types you first need to prevent the postback, then initiate in the callback function. This is explained in the following demo: http://demos.telerik.com/aspnet-ajax/window/examples/confirmserverclicks/defaultcs.aspx. The scripts file shows the different code for different button types and the demo description offers a detailed explanation.


    Regards,
    Marin Bratanov
    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 the blog feed now.

  13. Smartie
    Smartie avatar
    9 posts
    Member since:
    Jun 2007

    Posted 07 Jan Link to this post

    I would love to use the first example in the first link you have given.

    I get the following error when trying to set a value to onClick.

    Error 3 'Telerik.Web.UI.RadButton.Protected Overridable Sub OnClick(e As Telerik.Web.UI.ButtonClickEventArgs)' is not accessible in this context because it is 'Protected'.

    My control is dynamically added to the page.


  14. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 Jan Link to this post

    Hi,

    Please have a look into the following code snippet to show a Confirm on dynamically created RadButton click. 

    C#:

    protected void Page_Load(object sender, EventArgs e)
    {
            RadButton Button = new RadButton();
            Button.ID = "btnStandardConfirm";
            Button.Text = "Standard window.confirm";
            Button.OnClientClicking = "StandardConfirm";
            Button.Click+=new EventHandler(Button_Click);
            this.form1.Controls.Add(Button);
    }
    protected void Button_Click(object sender, EventArgs e)
    {
        RadButton btn = sender as RadButton;
        switch (btn.ID)
        {
            case "btnStandardConfirm":
                Label1.Text = "The <strong>StandardButton</strong> submitted the page at: " + DateTime.Now.ToString();
                break;
        }
    }

    Hope this will helps you.
    Thanks,
    Shinu.

  15. Smartie
    Smartie avatar
    9 posts
    Member since:
    Jun 2007

    Posted 17 Feb in reply to Shinu Link to this post

    Thank you, I have now gotten it working :)

Back to Top