access window event from inside the page in the radwindow?

4 posts, 1 answers
  1. Jacob Button
    Jacob Button avatar
    9 posts
    Member since:
    Aug 2009

    Posted 14 Oct 2009 Link to this post

    I have a RadWindow with a page inside of it. There is a javascript function on this page which (using RadAjaxManager) asynchronously updates another control every 10 seconds.  It does this through calling setTimeout on itself every time it fires.  This is working the way I want it to.  The problem is that once I close the window the javascript function is still firing every 10 seconds calling the the ajax postback.

    I want to be able to cancel the timeout when the window is closed but I have no idea how to detect that event from the page inside the window.  Any help?

    All of this code is in the page that is contained in the radwindow

    Javascript:
        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"
            <script language="javascript" type="text/javascript"
                function UpdateComments() { 
                    var ajaxManager = $find("<%= WorkbinItemAjaxManager.ClientID%>");   
                    ajaxManager.ajaxRequestWithTarget('<%= RefreshListBttn.UniqueID%>', ''); 
                    updatingComments = setTimeout ( "UpdateComments()", 10000 );   
                } 
     
                var updatingComments = setTimeout ( "UpdateComments()", 10000 ); 
     
            </script> 
        </telerik:RadScriptBlock> 

    AjaxManager
        <telerik:RadAjaxManager ID="WorkbinItemAjaxManager" runat="server"
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="RefreshListBttn"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="CommentsListBox" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
                <telerik:AjaxSetting AjaxControlID="InsertCommentBttn" > 
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="NewComment" /> 
                        <telerik:AjaxUpdatedControl ControlID="CommentsListBox" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager> 

    Controls
    <asp:TextBox ID="NewComment" runat="server" TextMode="MultiLine" EmptyMessage="Add Comment Here..." 
            Rows="3" Width="95%" style="margin-top:5px;"  /> 
     
    <asp:Button ID="InsertCommentBttn" runat="server" Text="Add Comment" OnClick="InsertComment" /> 
    <asp:Button ID="RefreshListBttn" runat="server" Text="Refresh List" OnClick="RefreshList" /> 
     
     
    <telerik:RadListBox ID="RadListBox1" runat="server" Height="100%" Width="100%"  
        DataSourceID="CommentsDataSource" DataKeyField="Comment_ID" OnItemDataBound="Comments_ItemDataBound" > 
    </telerik:RadListBox> 


    Every 10 seconds the javascript fires the RefreshButton onclick event which refreshes the ListBox.  When the window is closed I want to run some javascript like      clearTimeout(updatingComments);   which will stop the javascript from firing when the window is closed.


    On an unrelated note, but still something that's bothering me,  When I added the ListBox into the UpdatedControls on the AjaxManager the height=100% attribute of the list box stops working.  Whats the best way around this?  Thanks for any help.
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 Oct 2009 Link to this post

    Hi Jacob,

    By default, RadWindow instances are cached to speed up response time after the first time they are shown and is not destroyed, thats why the event fires even after window closes. You can prevent this caching by setting the DestroyOnClose property to True.

    Try setting the  DestroyOnClose property of RadWindow to True and see whether it helps.

    -Shinu.
  3. Jacob Button
    Jacob Button avatar
    9 posts
    Member since:
    Aug 2009

    Posted 16 Oct 2009 Link to this post

    :)

    Thank you shinu, that did the trick.

    Now any idea why my 100% height isn't working anymore?  I know I can set the height via javascript everytime the page is resized.... but that's just obnoxious.
  4. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 21 Oct 2009 Link to this post

    Hi Jacob,

    Try setting UpdatePanelsRenderMode to Inline and see if this fixes the problem.


    Kind regards,
    Georgi Tunev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top