Default to Cancel with RadConfirm

7 posts, 1 answers
  1. ColinBowern
    ColinBowern avatar
    51 posts
    Member since:
    Aug 2012

    Posted 02 Apr 2010 Link to this post

    I was surprised I didn't find anything in the search on this - how would you go about making the Cancel button the default one for a RadConfirm dialog?
  2. Answer
    Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 07 Apr 2010 Link to this post

    Hello ColinBowern,

    By design RadWindowManager will always focus the first button in the confirmation dialog. If you want to customize this behavior, you need to implement a custom confirm template. More information on RadWindowManager's templates is available here.

    Sincerely yours,
    Georgi Tunev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Lee
    Lee avatar
    16 posts
    Member since:
    Oct 2012

    Posted 12 Jul in reply to Georgi Tunev Link to this post

    Georgi,

    Can you be more specific as to what needs to be done in the template to change the focus to the cancel button. Also, once this is done, will pressing the spacebar fire the cancel button event?

    Lee

  5. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 13 Jul Link to this post

    Hi Lee,

    The easiest approach is to use JavaScript to focus the desired button after opening the dialog. Here is an example

    var dialog = radconfirm("sure?", callback);
    setTimeout(function () {
        //first option is for Classic RenderMode, second is for Lightweight RenderMode
        var cancelBtn = $telerik.$(".rwPopupButton", dialog.get_contentElement()).get(1) || $telerik.$(".rwCancelBtn", dialog.get_contentElement()).get(0);
        if (cancelBtn) {
            cancelBtn.focus();
        }
    }, 0);


    Regards,

    Marin Bratanov
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  6. Lee
    Lee avatar
    16 posts
    Member since:
    Oct 2012

    Posted 13 Jul in reply to Marin Bratanov Link to this post

    Unfortunately, I am calling radconfirm from vb.net server side. How do I set default in that case? Here is what I'm doing:

    RadWindowManager1.RadConfirm(....)

  7. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 13 Jul Link to this post

    Hi,

    You can use the OnClientShow event of the RadWindowManager to execute this code. Just replace the dialog variable with the sender argument: http://docs.telerik.com/devtools/aspnet-ajax/controls/window/client-side-programming/events/onclientshow.

    Here is an example:

    <telerik:RadWindowManager ID="RadWindowManager1" runat="server" OnClientShow="OnClientShowHandler" RenderMode="Lightweight"></telerik:RadWindowManager>
    <script>
        function OnClientShowHandler(sender, args) {
            setTimeout(function () {
                //first option is for Classic RenderMode, second is for Lightweight RenderMode
                var cancelBtn = $telerik.$(".rwPopupButton", sender.get_contentElement()).get(1) || $telerik.$(".rwCancelBtn", sender.get_contentElement()).get(0);
                if (cancelBtn) {
                    cancelBtn.focus();
                }
            }, 0);
        }
        function callback(arg) {
            alert(arg);
        }
    </script>

    protected void Page_Load(object sender, EventArgs e)
    {
        RadWindowManager1.RadConfirm("sure?", "callback", null, null, null, "title");
    }


    Regards,

    Marin Bratanov
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  8. Lee
    Lee avatar
    16 posts
    Member since:
    Oct 2012

    Posted 13 Jul in reply to Marin Bratanov Link to this post

    Thank you, Marin. It works perfectly.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017