Radwindow doesn't Hide When Press a Esc Key

6 posts, 0 answers
  1. Muhammad
    Muhammad avatar
    87 posts
    Member since:
    Oct 2012

    Posted 14 Feb 2011 Link to this post

    I am using RadWindow in my web application but when I press a escape key radwindow doesn't hide, when I checked the code of GetRadWindow() I found out that I am getting undefined object in my radwindow. I have also tried to hide my radwindow by using telerik shorcuts but the problem is that once it hides it never comes back again. I am showing my radwindow when user press a link button in my page. I don't understand that why I am getting undefined in my GetRadWindow() function. Any help would be greatly appreciated.

    function closeWindow() {
                var oWnd = GetRadWindow();            
                oWnd.hide();
            }


     function GetRadWindow()
    {
      var oWindow = null;
      
    if (window.rwCustomerListDialog)
         oWindow
     = window.rwCustomerListDialog;
      
    else if (window.frameElement.rwCustomerListDialog)
         oWindow
     = window.frameElement.rwCustomerListDialog;
      
    return oWindow;
    }  


            function pageLoad() {


                $addHandler(document, 'keydown', onKeypress);
            }


            function onKeypress(args) {


                if (args.keyCode == Sys.UI.Key.esc) {
                      closeWindow()
                }


            }

    <telerik:RadWindow ID="rwCustomerListDialog" runat="server" Title="Add Customer"
                    VisibleStatusbar="false" Behaviors="Move,Pin,Resize" InitialBehaviors="Pin" VisibleOnPageLoad="true"
                    Visible="false" OffsetElementID="rwCustomerListDialog" Height="500" Width="510"
                    Left="150px" KeepInScreenBounds="true" DestroyOnClose="true">
    <ContentTemplate>
     <table id="tblAddCustomer" border="0" cellpadding="0" cellspacing="0" width="100%"
                            runat="server">
                            <tr>
                                <td width="26%" align="right">
                                    <asp:Label ID="Label2" runat="server" Text="Customer code" Font-Bold="true" />
                                </td>
                                <td>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                </td>
                                <td>
                                    <asp:TextBox ID="tbCustomerCode" runat="server" Width="200px" />
                                    &nbsp;<asp:RequiredFieldValidator ID="rfvCustomerCode" runat="server" ErrorMessage="required!"
                                        ControlToValidate="tbCustomerCode"></asp:RequiredFieldValidator>
                                </td>
                            </tr>
    </table>
    </ContentTemplate>
    </telerik:RadWindow>
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Feb 2011 Link to this post

    Hello Jo,


    Access the RadWindow client object using $find() method instead of using GetRadWindow() and see whether that helps.

    Client code:
    function closeWindow() {
        var wnd = $find('<%= rwCustomerListDialog.ClientID %>');
        wnd.hide();
    }



    -Shinu.
  3. Muhammad
    Muhammad avatar
    87 posts
    Member since:
    Oct 2012

    Posted 14 Feb 2011 Link to this post

    Yes, that's work perfectly. Thank u.
  4. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 16 Feb 2011 Link to this post

    Hi Muhammad,

     I also suggest to examine the following online demo about the recently added keyboard support:

    http://demos.telerik.com/aspnet-ajax/window/examples/keyboardsupport/defaultcs.aspx

    Adding a shortcut for Esc key to close the RadWindow is as easy as setting a property instead of adding custom code.

    All the best,
    Svetlina
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  5. Billy Hasan
    Billy Hasan avatar
    18 posts
    Member since:
    May 2006

    Posted 06 Mar 2012 Link to this post

    If you click a link in one of the windows for the demo the shortcut keys no longer work. Is this by design? Is there a way around this? I would like to use the "Esc" key to close the rad window however if the user does anything within the window it no longer works.

    Thanks!
  6. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4529 posts

    Posted 07 Mar 2012 Link to this post

    Hello Billy,

    When you load an external page in the RadWindow it is actually loaded in an iframe. This means that it creates its own document and window objects, so events inside cannot bubble to the main page. This is why once the focus is set in the content page (i.e. you clicked a link) the parent page no longer knows what you do, so it cannot react. There is no way around this, because we cannot attach handlers to external pages. What you can do is add a onkeypress handler to your own content pages (in the case you can control this and they come from the same domain as the main page) and check for the Esc key. If it is pressed you can get a reference to the RadWindow an call its close() method from inside the content page.


    Regards,
    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.
Back to Top