This is a migrated thread and some comments may be shown as answers.
Radwindow doesn't Hide When Press a Esc Key
5 Answers 79 Views
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 1
Muhammad asked on 14 Feb 2011, 11:15 AM
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>

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 14 Feb 2011, 02:22 PM
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.
0
Muhammad
Top achievements
Rank 1
answered on 14 Feb 2011, 03:14 PM
Yes, that's work perfectly. Thank u.
0
Svetlina Anati
Telerik team
answered on 16 Feb 2011, 05:05 PM
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.
0
Billy
Top achievements
Rank 2
answered on 06 Mar 2012, 05:26 PM
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!
0
Marin Bratanov
Telerik team
answered on 07 Mar 2012, 04:44 PM
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.
Asked by
Muhammad
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Muhammad
Top achievements
Rank 1
Svetlina Anati
Telerik team
Billy
Top achievements
Rank 2
Marin Bratanov
Telerik team
Share this question
or