Prevent Window From Closing

1 posts, 0 answers
  1. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 17 Jun 2010 Link to this post


    RadControls version

    All AJAX versions

    .NET version

    All versions

    Visual Studio version

    All versions

    programming language


    browser support

    all browsers supported by RadControls

    Have you used code like that shown in RadWindow as Controls Container demo?

    Have you noticed that if your window has focus and the user presses Esc that the window closes? If you've written the page in such a way that you expect the window always to be open, you'll have found, as I did, that you have to reload the page to get the window back as you'll have prolly not included a control to open the thing.

    With the addition of a simple JS function, you can stop the window from being closed.

    When using a RadWindow like this, I generally hide the Titlebar and set Behavious="None". In addition to this, include the OnClientBeforeClose attribute and, in the called JS function, simply cancel the close request like so:
        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">  
            <script type="text/javascript">  
                function winDetailClosing(sender, e) {  
        <telerik:RadWindow ID="winDetail" runat="server" 
                <!-- Content goes here --> 
    This approach means that you can have other windows on the page that will close on Esc if that's what you want.

    So that's it. It's a simple solution to a question that seems to crop up a lot in the forums, one that, in an ideal world wouldn't be required 'cos the boys and girls at telerik towers would have found a way of building in a block for the Esc key if the user wanted it.


Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.