Prevent Window From Closing

Thread is closed for posting
1 posts, 0 answers
  1. CE8FD5B8-D57F-4131-8A9A-47DA58D4A301
    CE8FD5B8-D57F-4131-8A9A-47DA58D4A301 avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 17 Jun 2010 Link to this post

    Requirements

    RadControls version

    All AJAX versions

    .NET version

    All versions

    Visual Studio version

    All versions

    programming language

    .aspx

    browser support

    all browsers supported by RadControls


    PROJECT DESCRIPTION
    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) {  
                    e.set_cancel(true);  
                }  
            </script>   
        </telerik:RadScriptBlock> 
     
        <telerik:RadWindow ID="winDetail" runat="server" 
            Behaviors="None" 
            OnClientBeforeClose="winDetailClosing" 
            VisibleOnPageLoad="true" 
            VisibleStatusbar="false" 
            VisibleTitlebar="false">  
            <ContentTemplate> 
                <!-- Content goes here --> 
            </ContentTemplate> 
        </telerik:RadWindow> 
    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.

    --
    Stuart

Back to Top

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